Listing 1 GetFullPathNameW bug demonstration
#include <stdio.h> #include <windows.h> #define NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0])) void gfp_a() { char sz[_MAX_PATH + 1]; char *lpFilePart; GetModuleFileNameA(NULL, sz, NUM_ELEMENTS(sz)); printf("ANSI: "); GetFullPathNameA(sz, NUM_ELEMENTS(sz), sz, &lpFilePart); printf("%s\n", sz); } void gfp_w() { wchar_t sz[_MAX_PATH + 1]; wchar_t *lpFilePart; GetModuleFileNameW(NULL, sz, NUM_ELEMENTS(sz)); wprintf(L"Unicode: "); GetFullPathNameW(sz, NUM_ELEMENTS(sz), sz, &lpFilePart); wprintf(L"%s\n", sz); } int main(int argc, char** argv) { gfp_a(); gfp_w(); return 0; }