How to get encoding from MAPI message with PR_BODY_A tag (windows mobile)?
Posted
by SadSido
on Stack Overflow
See other posts from Stack Overflow
or by SadSido
Published on 2010-03-19T08:45:05Z
Indexed on
2010/03/19
8:51 UTC
Read the original article
Hit count: 287
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!
© Stack Overflow or respective owner