在MinGW g ++编译器中获取“tlhelp32.h”的编译错误

我正在编写一个简单的C ++应用程序来检查给定的exe文件示例:’a.exe’是否正在运行(Windows OS),我已经用Google搜索并在下面的链接中找到了一些代码。

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  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; } 

正如理查德·克里滕所说在“tlhelp32”之前添加“Windows.h”解决了这个问题,而上述代码中的函数startprocess()从未存在过,所以使用shellexecute()使其工作

例如:ShellExecute(NULL,“open”,“c:\ MinGW \ a.exe”,NULL,NULL,SW_SHOWDEFAULT);