#include <tlhelp32.h>
bool GetProcessHandle(TCHAR* processname)
{
if (processname == NULL)
return NULL;
HANDLE proc = NULL;
PROCESSENTRY32 pe;
DWORD id = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe))
return NULL;
while (1)
{
pe.dwSize = sizeof(PROCESSENTRY32);
if (Process32Next(hSnapshot, &pe) == FALSE)
break;
if (lstrcmpi(pe.szExeFile, processname) == 0)
{
id = pe.th32ProcessID;
break;
}
}
CloseHandle(hSnapshot);
if (id != 0)
return true;
return false;
}
QString MyLauncher::returnOutIP()
{
return GetNetIP(GetHtml("http://www.3322.org/dyndns/getip"));
}
QString MyLauncher::GetHtml(QString url)
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
QByteArray responseData;
QEventLoop eventLoop;
QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
eventLoop.exec();
responseData = reply->readAll();
return QString(responseData);
}
QT获取公网IP
最新推荐文章于 2024-04-17 18:06:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)