在vs2010下,宽字符与单字节字符使用很蛋疼,以下是连个简单的函数可以做到之间的良好转化:
(1)MultiByteToWideChar
(2)WideCharToMultiByte
PSTR str1 = new char[20];
memset(str1,0,20);
memcpy(str1,"xwl,hello world!",20);
printf(str1);
int needLength = MultiByteToWideChar(CP_ACP,0,str1,20,NULL,0);
PWSTR pWideCharStr =NULL;
pWideCharStr = (PWSTR)HeapAlloc(GetProcessHeap(),0,needLength*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP,0,str1,20,pWideCharStr,needLength);
HeapFree(GetProcessHeap(),0,pWideCharStr);