Unicode MAPI ****
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Unicode MAPI ****

  1. #1
    Join Date
    May 2005
    Posts
    25

    Unicode MAPI ****

    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.

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Unicode MAPI ****

    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

  3. #3
    Join Date
    May 2005
    Posts
    25

    Re: Unicode MAPI ****

    Quote Originally Posted by wildfrog
    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.

  4. #4
    Join Date
    Jan 2010
    Location
    Malaysia
    Posts
    15

    Re: Unicode MAPI ****

    Quote Originally Posted by ShadowCoder View Post
    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.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,797

    Re: Unicode MAPI ****

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    Manual says the email client may support UTF8, on Vista and later.

    gg

  6. #6
    Join Date
    Sep 2004
    Location
    Redlands, CA
    Posts
    74

    Re: Unicode MAPI ****

    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?

  7. #7
    Join Date
    Nov 2003
    Posts
    1,797

    Re: Unicode MAPI ****

    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.

    gg

  8. #8
    Join Date
    Jan 2010
    Location
    Malaysia
    Posts
    15

    Re: Unicode MAPI ****

    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.

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,845

    Re: Unicode MAPI ****

    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.

  10. #10
    Join Date
    Jan 2010
    Location
    Malaysia
    Posts
    15

    Re: Unicode MAPI ****

    Quote Originally Posted by OReubens View Post
    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.
    Yup, I do agree this is the safer way.Thanks . I found some guideline on how to do the conversion.
    http://www.codeguru.com/forum/showthread.php?t=231165

  11. #11
    Join Date
    Jan 2010
    Location
    Malaysia
    Posts
    15

    Re: Unicode MAPI ****

    Quote Originally Posted by Ming Soon View Post
    Yup, I do agree this is the safer way.Thanks . I found some guideline on how to do the conversion.
    http://www.codeguru.com/forum/showthread.php?t=231165
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center