In the end I have used the following code to make sure that I store proper utf-8 strings from what I recieve (it's for an ISAPI extension hence UNICODE is not used)
#ifndef _UNICODE
CString CStaticTools::MakeUTF8Compatible(const CString & strData)
{
int nSize = MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,strData,-1,NULL,0);
if ( nSize != 0 )
return strData;
nSize = MultiByteToWideChar(CP_ACP,MB_ERR_INVALID_CHARS,strData,-1,NULL,0);
if ( nSize == 0 )
return strData;
WCHAR * pBuffer= new WCHAR[nSize];
MultiByteToWideChar(CP_ACP,0,strData,-1,pBuffer,nSize);
BOOL bUsed = false;
int nUtfSize = WideCharToMultiByte(CP_UTF8,0,pBuffer,-1,NULL,0,NULL,NULL);
if ( nUtfSize == 0)
{
delete pBuffer;
return strData;
}
char * pDest = new char[nUtfSize];
WideCharToMultiByte(CP_UTF8,0,pBuffer,-1,pDest,nUtfSize,NULL,NULL);
CString strResult = pDest;
delete [] pBuffer;
delete pDest;
return strResult;
}
#endif
Please tell me if I have missed out something
Thanks Philippe (merci!) and nv3!