Your starting point seems incorrect; you cannot have Unicode characters in an array defined as
char* pData
. This is (at best) multibyte data so doing a straight
memcpy()
to a
wchar_t
array still leaves you with multibyte characters. As Superman mentioned you need to convert it to Unicode (assuming that is what you are trying to achieve).
However I suspect the basic problem is your use of
wcout
to display the characters. This stream accepts Unicode characters; however you are not passing Unicode characters so your data gets converted to garbage. Try the following:
int Convertchar_wchar(char* pData, int pDataLength)
{
cout << pData << endl;
}
int Convertchar_wchar(char* pData, int pDataLength)
{
wchar_t wcsQuery = new wchar_t[pDataLength + 1];
MultiByteToWideChar(CP_UTF8, 0, pData, pDataLength, wcsQuery, pDataLength + 1);
wcout << wcsQuery << endl;
delete [] wcsQuery;
}