楼上的各位,报下面的错误: error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'unsigned short *' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
说明你当前的工程为Unicode编码的
你这样写: int len = WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strName,-1,NULL,0,NULL,NULL); char *pszText = new char[len+1]; memset(pasText,len,sizeof(pszText)); WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strName,-1,pszText,len,NULL,NULL);Debug下跟一下,看执行完后,pszText的值。
第二个工程是_MBCS,代表是多字节字符集
你把第一个工程也改成_MBCS试试
好像是widechartoanti什么来着
WCHAR szName[MAX_PATH];
//memset(szName, 0, MAX_PATH);
int n = MultiByteToWideChar(CP_UTF8, 0, strName.GetBuffer(nLen), nLen, szName, MAX_PATH);
*(szName + n) = 0;
TRACE("%s\r\n", szName);
是这个函数,但是这个函数在第一个工程中会报错。
error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
int len = WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strName,-1,NULL,0,NULL,NULL);
char *pszText = new char[len+1];
memset(pasText,len,sizeof(pszText));
WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strName,-1,pszText,len,NULL,NULL);Debug下跟一下,看执行完后,pszText的值。