Hello, I have this code:

void GetProcId(char* ProcName)
		PROCESSENTRY32   pe32;
		HANDLE         hSnapshot = NULL;

		pe32.dwSize = sizeof( PROCESSENTRY32 );
		hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

		if( Process32First( hSnapshot, &pe32 ) )
				if( _stricmp( pe32.szExeFile, ProcName ) == 0 )
			}while( Process32Next( hSnapshot, &pe32 ) );

		if( hSnapshot != INVALID_HANDLE_VALUE )
			CloseHandle( hSnapshot );

		ProcId = pe32.th32ProcessID;

But I keep getting:

argument of type "WCHAR *" is incompatible with parameter of type "const char *
'_stricmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'

I dont know what to do anymore, I'm researching this kind of code for over 2h!

Edited by lelejau: n/a

7 Years
Discussion Span
Last Post by thelamb

You're compiling the code with unicode support. If you look at how szExeFile is declared, you'll see:

TCHAR     szExeFile[MAX_PATH];

Because you compile with unicode support, the compiler expands 'TCHAR' to 'WCHAR', which is a wide character.

So in your project settings, you should compile with 'multi-byte support', or change procname to TCHAR as well, and make sure the rest of your application is unicode.

However, if you fix this it will still give the same error. szExeFile is a fixed-length array, but the str*cmp functions take a char*.

You can do this by passing &pe32.szExeFile[0] to these functions.

Also note, it is better to use _strnicmp instead of _stricmp, as this takes a size parameter. If you decide to convert your application to unicode you need to use _wcsnicmp (this is off the top of my head, excuse me for typos).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.