MultiByteToWideChar// we want to convert an MBCS string in lpszA int nLen = MultiByteToWideChar(CP_ACP, 0,lpszA, -1, NULL, NULL); LPWSTR lpszW = new WCHAR[nLen]; MultiByteToWideChar(CP_ACP, 0, lpszA, -1, lpszW, nLen); // use it to call OLE here pI->SomeFunctionThatNeedsUnicode(lpszW); // free the string delete[] lpszW;
int nLen = MultiByteToWideChar(CP_ACP, 0,lpszA, -1, NULL, NULL);
LPWSTR lpszW = new WCHAR[nLen];
MultiByteToWideChar(CP_ACP, 0,
lpszA, -1, lpszW, nLen);
// use it to call OLE here
pI->SomeFunctionThatNeedsUnicode(lpszW);
// free the string
delete[] lpszW;
{
ULONG cCharacters;
DWORD dwError;
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
cCharacters = strlen(pszA)+1;
*ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);
if (NULL == *ppszW)
return E_OUTOFMEMORY;
if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,*ppszW, cCharacters))
{
dwError = GetLastError();
CoTaskMemFree(*ppszW);
*ppszW = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}