1. 程式人生 > >Use Unicode Character Set: CString 轉為 char*

Use Unicode Character Set: CString 轉為 char*

          由於DXUT框架中屬性 - 工程屬性 - Configuration Properties - General - Character Set的配置需要Use Unicode Character Set,導致Character Set:Use Multi-Byte Character Set的CString轉換到char*失效,本文Use Unicode Character Set設定轉換的方法如下:

CString filename;

char* g_szMovieName;

int length = filename.GetLength();

int nBytes = WideCharToMultiByte(CP_ACP,0,filename,length,NULL,0,NULL,NULL);

 g_szMovieName = new char[nBytes + 1];

memset(g_szMovieName,0,length + 1);

WideCharToMultiByte(CP_OEMCP,0,filename,length,g_szMovieName,nBytes,NULL,NULL);

g_szMovieName[nBytes] = 0;