在 MinGW g++ 编译器中获取 "tlhelp32.h" 的编译错误
Getting compilation error for "tlhelp32.h" in MinGW g++ compiler
我正在编写一个简单的 C++ 应用程序来检查给定的 exe 文件示例:'a.exe' 是否为 运行(windows OS),我已经用谷歌搜索了并在下面 link.
中找到了一些代码
上面提到的代码使用了头文件"tlhelp32.h"。我只是复制了代码并做了一些必要的更改然后在 MinGW 中进行了编译,下一个问题来了,该头文件中提到的所有数据类型都被错误了
ex: 'DWORD' does not name a type, 'LONG' does not name a type, 'WCHAR' does not name a type,'CHAR' does not name a type
我以前从未遇到过现有头文件编译失败的问题(是的,我已经检查过了)。
非常感谢对此的任何帮助。
代码如下:
#include <tlhelp32.h>
int main()
{
PROCESSENTRY32 pe32 = {0};
HANDLE hSnap;
int iDone;
int iTime = 60;
bool bProcessFound;
while(true) // go forever
{
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe32.dwSize = sizeof(PROCESSENTRY32);
Process32First(hSnap,&pe32); // Can throw away, never an actual app
bProcessFound = false; //init values
iDone = 1;
while(iDone) // go until out of Processes
{
iDone = Process32Next(hSnap,&pe32);
if (strcmp(pe32.szExeFile,"a.exe") == 0) // Did we find our process?
{
bProcessFound = true;
iDone = 0;
}
}
if(!bProcessFound) // if we didn't find it running...
{
startProcess("C:\MinGW\"+"a.exe",""); // start it
}
Sleep(iTime*10); // delay x amount of seconds.
}
return 0;
}
正如 Richard Critten 所说,在 "tlhelp32" 之前添加 "Windows.h" 可以解决问题,而且上面代码中的函数 startprocess() 从未存在过,因此请使用 shellexecute() 使其工作
ex: ShellExecute(NULL, "open", "c:\MinGW\a.exe", NULL, NULL, SW_SHOWDEFAULT);
我正在编写一个简单的 C++ 应用程序来检查给定的 exe 文件示例:'a.exe' 是否为 运行(windows OS),我已经用谷歌搜索了并在下面 link.
中找到了一些代码
上面提到的代码使用了头文件"tlhelp32.h"。我只是复制了代码并做了一些必要的更改然后在 MinGW 中进行了编译,下一个问题来了,该头文件中提到的所有数据类型都被错误了
ex: 'DWORD' does not name a type, 'LONG' does not name a type, 'WCHAR' does not name a type,'CHAR' does not name a type
我以前从未遇到过现有头文件编译失败的问题(是的,我已经检查过了)。
非常感谢对此的任何帮助。
代码如下:
#include <tlhelp32.h>
int main()
{
PROCESSENTRY32 pe32 = {0};
HANDLE hSnap;
int iDone;
int iTime = 60;
bool bProcessFound;
while(true) // go forever
{
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe32.dwSize = sizeof(PROCESSENTRY32);
Process32First(hSnap,&pe32); // Can throw away, never an actual app
bProcessFound = false; //init values
iDone = 1;
while(iDone) // go until out of Processes
{
iDone = Process32Next(hSnap,&pe32);
if (strcmp(pe32.szExeFile,"a.exe") == 0) // Did we find our process?
{
bProcessFound = true;
iDone = 0;
}
}
if(!bProcessFound) // if we didn't find it running...
{
startProcess("C:\MinGW\"+"a.exe",""); // start it
}
Sleep(iTime*10); // delay x amount of seconds.
}
return 0;
}
正如 Richard Critten 所说,在 "tlhelp32" 之前添加 "Windows.h" 可以解决问题,而且上面代码中的函数 startprocess() 从未存在过,因此请使用 shellexecute() 使其工作
ex: ShellExecute(NULL, "open", "c:\MinGW\a.exe", NULL, NULL, SW_SHOWDEFAULT);