Unicode模式下char*与LPCTSTR类型的转化

 使用MultiByteToWideChar转换:步骤:

1. DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, sText, -1, NULL, 0); 

2. wchar_t *pwText = new wchar_t[dwNum]; 

if(!pwText) 

  delete []pwText; 

3.成ASCII码 

MultiByteToWideChar (CP_ACP, 0, psText, -1, sText, dwNum); 

4.释放占用的内存: 

delete []psText; 

 

 

一下为转载的宽字符转多字符的例子

wchar_t wText[20] = {L"宽字符转换实例!OK!"}; 

DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE); 

char *psText; 

psText = new char[dwNum]; 

if(!psText) 

  delete []psText; 

WideCharToMultiByte (CP_OEMCP,NULL,lpcwszStr,-1,psText,dwNum,NULL,FALSE); 

delete []psText

你可能感兴趣的:(mfc,字符转换)