Code: Select all
#include <windows.h>
/******************************************************************************
Function: Convert ANSI to UNICODE
Author: Gabriel Fleseriu
Source: http://www.codeguru.com/forum/showthread.php?t=231165
******************************************************************************/
BSTR ConvertANSItoUNICODE( char * ansistr ) {
int lenA = lstrlenA(ansistr);
int lenW;
BSTR unicodestr;
lenW = ::MultiByteToWideChar(CP_ACP, 0, ansistr, lenA, 0, 0);
if (lenW > 0)
{
// Check whether conversion was successful
unicodestr = ::SysAllocStringLen(0, lenW);
::MultiByteToWideChar(CP_ACP, 0, ansistr, lenA, unicodestr, lenW);
}
else
{
// handle the error....
return NULL;
}
//// when done, free the BSTR
::SysFreeString(unicodestr);
return unicodestr;
}