The main problem is that you using ANSI strings instead of UNICODE-UTF16. The main solution is to use TCHAR
compatible entry point _tmain
, it will be compatible either with UNICODE or ANSI consider project settings as the same GetFullPathName
will be GetFullPathNameA
for ANSI configuration and GetFullPathNameW
for UNICODE.
Example
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR* fileExt;
TCHAR szDir[256];
GetFullPathName(argv[0], 256, szDir, &fileExt);
return 0;
}
To display ANSI or UNICODE string to your program you may use this statement in the begining of your main function
#if defined(UNICODE) || defined(_UNICODE)
#define consoleOut std::wcout
#else
#define consoleOut std::cout
#endif
than display your strings as
consoleOut << szDir << std::endl;
the overall program will be
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#if defined(UNICODE) || defined(_UNICODE)
#define consoleOut std::wcout
#else
#define consoleOut std::cout
#endif
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR* fileExt;
TCHAR szDir[256];
GetFullPathName(argv[0], 256, szDir, &fileExt);
consoleOut << szDir << std::endl;
return 0;
}
And the result.
