现在的位置: 首页 > 综合 > 正文

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

2013年12月10日 ⁄ 综合 ⁄ 共 549字 ⁄ 字号 评论关闭

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);
}

【上篇】
【下篇】

抱歉!评论已关闭.