16,472
社区成员
发帖
与我相关
我的任务
分享
//宽字节转多字节
char* TCHAR2STRING(const TCHAR * STR)
{
int iLen = WideCharToMultiByte(CP_ACP, 0, STR, -1, NULL, 0, NULL, NULL);
char* chRtn =new char[iLen*sizeof(char)];
memset(chRtn, 0, iLen);
WideCharToMultiByte(CP_ACP, 0, STR, -1, chRtn, iLen, NULL, NULL);
chRtn[iLen] = 0;
return chRtn;
}
void Test()
{
TCHAR tz[256] = L"aaa";
string str = TCHAR2STRING(tz); //不知道转换时那个new出来的对象如何释放,导致内存不断飙升
}
void main()
{
while(1)
Test();
}
bool TCHAR2STRING(LPCWSTR lpszWstr, //宽字符串
LPSTR lpszMstr,//转换后的多字节字符串
int Len) //缓冲区大小