简体   繁体   中英

Compare WCHAR String with Const Char in C?

I have written a code in C which will use the Process32First() API to get information about the process. All the information is stored in the PROCESSENTRY32 structure defined here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684839%28v=vs.85%29.aspx

pe32 is the name of the PROCESSENTRY32 structure. process name will be: pe32.szExeFile

I can print it this way:

_tprintf(TEXT("Process name: %s\n"),pe32.szExeFile);

now, I want to compare the process name with a specific process like explorer.exe

this is what I am doing:

if(!wcscmp(pe32.szExeFile, _T("explorer.exe"))
{
 perform some action here;
}

It does not work.

In MS Visual Studio 2008, the data type for szExeFile member of the PROCESSENTRY32 structure is: WCHAR tagPROCESSENTRY32::szExeFile[260]

So, I think it is a Wide Character String?

and explorer.exe is a normal character string (const char *), pointer to an array of characters.

how can I compare szExeFile with a normal string?

I find these data types quite confusing and I hope to understand them better with this example.

Thanks.

Change your if to use wide string for "explorer.exe" as

if(!wcscmp(pe32.szExeFile, L"explorer.exe")

ie use L"explorer.exe" to compare with wide string.

You can also settings in your VC project to use UNICODE character set, through Project->Settings->Configuration Properties->General .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM