char*(LPSTR)与wchar_t*(LPTSTR) 相互转换的函数

来源:互联网 发布:儿童学编程 软件 编辑:程序博客网 时间:2024/05/21 22:43

void CharToWchar(const char *constCharString, TCHAR *outWchar) 
{
int   nLen = strlen(constCharString) + 1;   
int   nwLen = MultiByteToWideChar(CP_ACP, 0, constCharString, nLen, NULL, 0);  
    
TCHAR   *wString;
wString = new TCHAR[nwLen];


MultiByteToWideChar(CP_ACP, 0, constCharString, nLen, wString,nwLen);
_tcscpy(outWchar,wString);//   wcscpy(outWchar,wString);


delete[] wString;
}
void WCharToChar(TCHAR *InWchar , char *OutStr)
{
  DWORD dwNum=WideCharToMultiByte(CP_OEMCP,NULL,InWchar,-1,NULL,0,NULL,FALSE)+1;
  WideCharToMultiByte(CP_OEMCP,NULL,InWchar,wcslen(InWchar),OutStr,dwNum,NULL,FALSE);
}