在 MinGW g++ 编译器中获取"tlhelp32.h"的编译错误
Getting compilation error for "tlhelp32.h" in MinGW g++ compiler
我正在编写一个简单的c++应用程序,用于检查给定的exe文件示例:'a.exe'是否正在运行(windows操作系统),我已经在谷歌上搜索并在以下链接中找到了一些代码。
http://stackoverflow.com/questions/3355379/how-do-i-find-out-if-a-exe-is-running-in-c 上面提到的代码使用了一个头文件"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:MinGWa.exe", NULL, NULL, SW_SHOWDEFAULT);