Hi, everyone!
I am developing a program, that handles incoming e-mail and sms through windows-mobile MAPI. The code basically looks like that:
ulBodyProp = PR_BODY_A;
hr = piMessage->OpenProperty(ulBodyProp, NULL, STGM_READ, 0, (LPUNKNOWN*)&piStream);
if (hr == S_OK)
{
// ... get body size in bytes ...
STATSTG statstg;
piStream->Stat(&statstg, 0);
ULONG cbBody = statstg.cbSize.LowPart;
// ... allocate memory for the buffer ...
BYTE* pszBodyInBytes = NULL;
boost::scoped_array<BYTE> szBodyInBytesPtr(pszBodyInBytes = new BYTE[cbBody+2]);
// ... read body into the pszBodyInBytes ...
}
That works and I have a message body. The problem is that this body is multibyte encoded and I need to return a Unicode string. I guess, I have to use ::MultiByteToWideChar() function, but how can I guess, what codepage should I apply? Using CP_UTF8 is naive, because it can simply be not in UTF8. Using CP_ACP works, well, sometimes, but sometimes does not. So, my question is: how can I retrieve the information about message codepage. Does MAPI provide any functions for it? Or is there a way to decode multibyte string, other than MultiByteToWideChar()?
Thanks!