“tlhelp32.h”的编译错误在MinGW g ++编译器中 [英] Getting compilation error for "tlhelp32.h" in MinGW g++ compiler

查看:1053
本文介绍了“tlhelp32.h”的编译错误在MinGW g ++编译器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的C ++应用程序,检查给定的exe文件示例:'a.exe'是否正在Windows操作系统上运行,我已经google了,并在下面的链接中找到一些代码。 p>

http://stackoverflow.com/questions/3355379/how-do-i-find-out-if-a-exe-is-running-in-c

上述代码使用头文件tlhelp32.h。我刚刚复制的代码做了一些必要的更改,并在MinGW中完成,出现的问题所有的数据类型提到的头文件中错误ex:'DWORD'不命名一个类型,'LONG'不命名类型,'WCHAR'没有命名一个类型,'CHAR'不命名一个类型,



我从来没有面对这种问题,其中存在的头文件失败complie(是的,我检查了它)。



有人可以帮我这个。



代码如下:

  #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); //可以抛弃,从不是一个实际的应用程序

bProcessFound = false; //初始值
iDone = 1;

while(iDone)//直到退出进程
{
iDone = Process32Next(hSnap,& pe32);
if(strcmp(pe32.szExeFile,a.exe)== 0)//我们找到我们的过程吗?
{
bProcessFound = true;
iDone = 0;
}
}

if(!bProcessFound)//如果我们没有找到它运行...
{
startProcess(C: \\MinGW\\+a.exe,); // start it
}
Sleep(iTime * 10); // delay x amount of seconds。
}
return 0;

}


解决方案

Critten说在tlhelp32之前添加Windows.h解决了问题,并且更多的上述代码中的startprocess()从来不存在,所以使用shellexecute()使它工作



ex:ShellExecute(NULL,open,c:\MinGW\a.exe,NULL,NULL,SW_SHOWDEFAULT);


I am in the process of creating a simple C++ app that checks whether the given exe file example:'a.exe' is running or not on windows OS, i have googled and found some code in the below link.

http://stackoverflow.com/questions/3355379/how-do-i-find-out-if-a-exe-is-running-in-c

The code mentioned above uses a header file "tlhelp32.h". I just copied the code did some necessary changes and complied it in MinGW , there comes the problem all of the datatypes mentioned in that header files are errored out 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,

I never before faced this kind of issues where a existed header file has failed to complie (yes it exist i checked it).

can somebody help me with this.

code below:

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

}

解决方案

As Richard Critten said adding "Windows.h" before "tlhelp32" resolves the issue and more over a function startprocess() in the above code has never exist so use shellexecute() to make it to work

ex: ShellExecute(NULL, "open", "c:\MinGW\a.exe", NULL, NULL, SW_SHOWDEFAULT);

这篇关于“tlhelp32.h”的编译错误在MinGW g ++编译器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆