In a C++ program, I am trying to read data from MSSQL database using OLE DB. The column I am trying to read is a VARCHAR type. The data in the column is imported from a multi-value database. Sometimes the data in the column has a delimiter in it. The delimiter is a value marker (0Xfd). I covert the data read from the table to a char * like this:
retcode = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)pDBColumnAccess[nCol].pData, -1, (char *)pReadBuf, pDBColumnAccess[nCol].cbDataLen, NULL, NULL);
Everything is fine if the data does not contain above mentioned delimiter – value marker (0xfd). But when the delimiter is there, in the converted data the value marker is replaced by some junk characters.
Shouldn’t I do a conversion to char * in the case of VARCHAR? Is it enough to just copy the data as it is without any coversion?
The
WideCharToMultiByteconverts from UTF-16, yet there is no such thing as0xFDcharacter in UTF-16. All characters are encoded as at least 2 bytes. Did you actually mean0x00FD(or even0xFD00)?Also, UTF-8 (your “target” encoding since you specified
CP_UTF8) does not guarantee that all characters will be encoded in just one byte.According to UTF Converter:
00FDconverts to UTF-8C3 BD.FD00converts to UTF-8EF B4 80.Is that what you are getting?