Using MAPI in C application

This is a discussion on Using MAPI in C application within the C Programming forums, part of the General Programming Boards category; I am trying to add MAPI functionality to my C application. Can anyone give me an idea of how to ...

  1. #1
    cev
    cev is offline
    Registered User
    Join Date
    Dec 2007
    Location
    Moyock, NC
    Posts
    3

    Using MAPI in C application

    I am trying to add MAPI functionality to my C application. Can anyone give me an idea of how to best do this.

    I have to add the MAPI32.dll at runtime using LoadLibrary and using typedef's for the functions. I don't have any experience doing it this way and the examples that I have found on the web are very simplistic. All I want to do is be able to call the MAPIResolveName and MAPIAddress functions from my C application.

  2. #2
    cev
    cev is offline
    Registered User
    Join Date
    Dec 2007
    Location
    Moyock, NC
    Posts
    3

    Talking

    Ok, I've got it to compile and run but I am getting an unhandled exception when it calls lpfnMAPIResolveName. Can anyone see anything that might be wrong with my code?

    Code:
    prototypes...
    
    typedef MediumInt (CALLBACK* LPFNMAPIRESOLVENAME)(LHANDLE lhSession, ULONG param, LPTSTR name, Flags16 options, ULONG reserved, MapiRecipDesc * lppRecip);
    typedef MediumInt (CALLBACK* LPFNMAPIFREEBUFFER)(LPVOID pv);
    
    code...
    
    Bool Dynlink SmpCheckName( PSMP pSmp, PWND pWnd, PSTR pStr, MediumInt size )
    {
       HINSTANCE   hMapi;
       MediumInt   rtn;
       Flags16     options;
       LPFNMAPIRESOLVENAME lpfnMAPIResolveName;
       LPFNMAPIFREEBUFFER  lpfnMAPIFreeBuffer;
       
       SmpAssert( pSmp );
                                   
       BitSet( options, MAPI_DIALOG );
       BitSet( options, MAPI_NEW_SESSION );
       
       hMapi = LoadLibrary( "MAPI32.DLL" );
       if( hMapi == NULL )
          return False;
          
       lpfnMAPIResolveName = (LPFNMAPIRESOLVENAME)GetProcAddress( hMapi, "MAPIResolveName" );
       lpfnMAPIFreeBuffer = (LPFNMAPIFREEBUFFER)GetProcAddress( hMapi, "MAPIFreeBuffer" );
       
       rtn = lpfnMAPIResolveName( 0, (ULargeInt) WndAsHwnd( pWnd ), pStr, options, 0, pSmp->mapiDesc );
       
       if( rtn != SUCCESS_SUCCESS )
       {  FreeLibrary( hMapi );
          return False;
       }
       
       StrCopy( pStr, size, pSmp->mapiDesc->lpszAddress );
       lpfnMAPIFreeBuffer( pSmp->mapiDesc );   
       FreeLibrary( hMapi );
       return True;   
                
    } /* End SmpCheckName */

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Perhaps check that lpfnMAPIResolveName is actually != NULL before trying to call it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    cev
    cev is offline
    Registered User
    Join Date
    Dec 2007
    Location
    Moyock, NC
    Posts
    3
    lpfnMAPIResolve wasn't NULL it had an assigned address, but the problem was my MapiDesc wasn't a stack variable and needed to be.

    Now it runs fine except it returns successful, but the address is NULL. After further research I find that this is a Microsoft issue where if your default browser is set to Outlook the lpszAddress returns NULL. There is a hotfix for this though, http://support.microsoft.com/kb/820369

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cleanup of the application...
    By Petike in forum Windows Programming
    Replies: 1
    Last Post: 08-16-2008, 05:23 PM
  2. Problem with com application
    By amardon in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2005, 05:50 AM
  3. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 03:33 AM
  4. Win application not very portable
    By swed in forum Windows Programming
    Replies: 5
    Last Post: 10-01-2001, 11:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21