对网上抄来的代码真要多个心眼才行!,最少看一遍啊
比如:
WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,targetLen,NULL,NULL); str = (char*)pTargetData; BYTE * pTargetData =new BYTE[targetLen+1]; wchar_t * pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); MultiByteToWideChar(sourceCodepage,0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen); int targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,0,NULL,NULL); delete pTargetData; delete pUnicode;
看到这种代码简直无语, 经典的内存泄露啊,多留个心眼吧,不管自己写的代码还是别人的代码,多审查两遍是不会错的