WinApi unicode问题

WinApi unicode问题,c,winapi,unicode,C,Winapi,Unicode,我有密码: 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", GetCurrent

我有密码:

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);

它应该创建一个文件“vdrXXXX.tmp”,其中XXXX是进程id。但是它返回奇怪的东西。比如unicode符号,然后是路径的一部分。我做错了什么?

在调用
MessageBox()
之前,您正在释放内存

在任何情况下,都不需要使用
HeapAlloc()
,只需使用
malloc()
。事实上,由于
GetTempFileName()
的最大缓冲区大小为
MAX\u PATH
,因此使用堆栈分配的缓冲区最容易做到这一点