In our app we are using MAPISendMail to send an email with an attachment. In ANSI mode everything works fine. However, once in Unicode mode it no longer works. The problem is that MapiFileDesc and MapiMessage only take LPSTR as strings. So when I have a Unicode file that is filled with Asian characters there is no way to pass that string to the MAPI stuff. Seems to me like I cannot use MAPI in this instance. Can anyone recommend another way of lauching the system's default email app and adding an attachment to it? Or if there is a way to modify the MAPI code that would work as well.
The MapiFileDesc and MapiMessage structures are taking LPTSTR, not LPSTR. LPTSTR is defined differently for Ansi (char*) and Unicode (wchat_t*)builds.
To use the unicode version you can do a:
Code:
#define UNICODE
#include <windows.h>
...
- petter
According to MSDN it uses LPTSTR but it lies. If you look at the source it is using LPSTR not LPTSTR. That's also why in Unicode if you do try to assign a string enclosed in _T("") to say MapiFileDesc.lpszPathName it will complain about not being able to convert to a char*. If it did actually use LPTSTR I wouldn't be seeing the errors I am seeing.
According to MSDN it uses LPTSTR but it lies. If you look at the source it is using LPSTR not LPTSTR. That's also why in Unicode if you do try to assign a string enclosed in _T("") to say MapiFileDesc.lpszPathName it will complain about not being able to convert to a char*. If it did actually use LPTSTR I wouldn't be seeing the errors I am seeing.
I totally agree with you ShadowCoder. You are right. I got the same error too!
Last edited by Ming Soon; July 23rd, 2010 at 05:10 AM.
so what would be the right solution for unicode? I am currently use MAPISendMail to launch default mail client. Though, if I attach files with unicode characters in it, it returns error MAPI_E_ATTACHMENT_OPEN_FAILURE. I am on XP. Any idea?
Did you follow the instructions for "Unicode Support" at the link I posted?
Though I would imagine that the encoding of an attached file shouldn't matter. If I attach a TXT, ZIP, DOC, etc... it just shows up as-is on the other end.
Since MapiFileDesc and MapiMessage structures said that it only take LPSTR(or in others word it is equivalent to char*).
According to your replied. We need to put in utf8. May i know how to convert a CString into utf8 and put inside LPSTR?
Example:
CString xxx;
//! TODO
LPSTR zzz;
I need xxx convert to utf8 and put it inside zzz.Any idea?
Last edited by Ming Soon; September 3rd, 2010 at 02:50 AM.
MAPI and Unicode don't work well. There are a few clients that support the unicode version of the call. But then you'll be severely limiting your users.
The safe thing to do is to use the ANSI version, and convert any unicode filenames to the ansi equivalent. The simple way to get a valid ansi name is to get the Short (DOS) name for the file.
MAPI and Unicode don't work well. There are a few clients that support the unicode version of the call. But then you'll be severely limiting your users.
The safe thing to do is to use the ANSI version, and convert any unicode filenames to the ansi equivalent. The simple way to get a valid ansi name is to get the Short (DOS) name for the file.
I did try by using conversion guideline I found from above thread,but I notice that the Unicode will only work when your current operating system is taiwan/korean/japanese. Because the conversion type is CP_ACP.
Bookmarks