2014년 10월 27일 월요일

char* to wchar_t*(LPWSTR)

LPWSTR ConvertLPCSTRToLPWSTR (char* pCstring)
{
 LPWSTR pszOut = NULL;
 if (pCstring != NULL)
 {
  int nInputStrLen = strlen (pCstring);
  // Double NULL Termination
  int nOutputStrLen = MultiByteToWideChar(CP_ACP, 0, pCstring, nInputStrLen, NULL, 0) + 2;
  pszOut = new WCHAR [nOutputStrLen];

  if (pszOut)
  {
   memset (pszOut, 0x00, sizeof (WCHAR)*nOutputStrLen);
   MultiByteToWideChar (CP_ACP, 0, pCstring, nInputStrLen, pszOut, nInputStrLen);
  }

 }

 return pszOut;
}

[사용]

char * str = new char[strlen("ASHOK") + 1];

strcpy(str, "ASHOK");

WCHAR * pwStr = ConvertLPCSTRToLPWSTR(str);

댓글 없음: