Vinicius Horta
Vinicius Horta

Reputation: 233

Why do I get a hexadecimal value when I print a string?

What's wrong? Why do i get 0x0000etc on output?

int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

    if( !hSnapshot )
        return -1;

    PROCESSENTRY32W pe32w;
    memset( &pe32w, 0, sizeof( pe32w ) );
    pe32w.dwSize = sizeof( PROCESSENTRY32W );
    Process32First( hSnapshot, &pe32w );
    do
    {
        std::cout << pe32w.szExeFile << std::endl;
    } while( Process32Next( hSnapshot, &pe32w ) );

    CloseHandle( hSnapshot );

    return 0;
}

Upvotes: 0

Views: 208

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 993085

This is likely because your PROCESSENTRY32W structure is using wchar_t types for szExeFile, and std::cout does not understand how to handle wide characters. In this case it simply prints the pointer value instead.

You may be able to use std::wcout to print wide character values.

Upvotes: 2

Related Questions