I am trying to load the name of an image using its VM address by calling GetModuleFileName() which seems to return the value correctly into a TCHAR[] array. I am able to display the data correctly using MessageBox() but cout << seems to display some funky hexadecimal number.
TCHAR buf[MAX_PATH];
HMODULE hProc = LoadLibrary(TEXT("kernel32.dll"));
GetModuleFileName(hProc, buf, MAX_PATH);
cout << buf; //Produces the odd number
MessageBox(NULL, buf, NULL, MB_OK); //Produces correct filepath
FreeLibrary(hProc);
Am I supposed to set a flag for cout so it knows to print it correctly? Thank you!
TCHAR. Use e.g.wchar_t. Then you know better what you're doing and what you're dealing with.TCHARis a macro (pure text substitution) that is defined as eithercharorwchar_t, depending on whether the symbolUNICODEwas defined when you included the relevant header, usually<windows.h>. Similarly,TEXTaddsLprefix or not. This means that code that works withUNICODEdefined, may and probably will not compile whenUNICODEis not defined. TheTscheme originally supported Windows 9x, but as of 2011 it is just a problematic extra layer of obfuscation. For example, it prevented you from knowing that you dealt withwchar_t. Cheers & hth.,