Hey all,
Im trying to write some code that checks if a certain process is running which uses the PROCESSENTRY32 structure. The variable szExeFile is returning a WCHAR (even though msdn says its a supposed to be a TCHAR). This is my code:
Code:
HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32* processInfo=new PROCESSENTRY32;
processInfo->dwSize=sizeof(PROCESSENTRY32W);
while(Process32Next(hSnapShot,processInfo)!=FALSE)
{
if((strstr(processInfo->szExeFile, "myprocess"))!=NULL)
{
MessageBox(NULL, processInfo->szExeFile, _T("hi"), MB_OK);
delete[] processInfo;
CloseHandle(hSnapShot);
return true;
}
}
delete[] processInfo;
CloseHandle(hSnapShot);
return false;
I get an error when I compile saying
error C2665: 'strstr' : none of the 2 overloads could convert all the argument types
d:\program files\microsoft visual studio 8\vc\include\string.h(163): could be 'const char *strstr(const char *,const char *)'
d:\program files\microsoft visual studio 8\vc\include\string.h(187): or 'char *strstr(char *,const char *)'
while trying to match the argument list '(WCHAR [260], const char [8])'
I then change the strstr command to
Code:
if((strstr((char*)processInfo->szExeFile, "myprocess"))!=NULL)
it compiles fine but the strstr always returns NULL even though im 100% sure that the process myprocess is running. Therefore the (char*)processInfo-szExeFile must be returning junk values.
Any idea how to solve this?
Thanks