I have the code:
wchar_t* temp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1000 * sizeof(wchar_t));
wchar_t* temp2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1000 * sizeof(wchar_t));
GetTempPathW(1000, temp);
GetTempFileNameW(temp, L"vdr", GetCurrentProcessId(), temp2);
HeapFree(GetProcessHeap(), 0, temp2);
MessageBoxW(0,temp2,0,0);
It should make a file “vdrXXXX.tmp” with XXXX to be the processs id. But it returns strange things. Like unicode symbols and then part of the path. What I’m doing wrong?
You are freeing the memory before calling
MessageBox().In any case, there’s no need to use
HeapAlloc(), just usemalloc(). In fact, sinceGetTempFileName()has a maximum buffer size ofMAX_PATH, it’s easiest to do this with stack allocated buffers.