#define USES_IID_IABContainer
    #define USES_IID_IMailUser
    #define USES_IID_IAddrBook
    #define INITGUID
    #include <mapix.h>
    #include <mapiguid.h>
    #include <mapidefs.h>
    #include <mapiutil.h>
    HWND g_hWnd = NULL;  // Set g_hWnd to a window handle in your app.
                         // Specifically the window that will be the parent
                         // of the Address Book dialog.
    HRESULT Logon ( LPMAPISESSION *pSession )
    {
       HRESULT hRes = S_OK;
       LPMAPISESSION pLocalSession = NULL;
       ULONG ulFlags = 0L;
       if ( FAILED ( hRes = MAPIInitialize ( NULL ) ) )
          goto Quit;
       ulFlags = MAPI_EXTENDED |
                 MAPI_LOGON_UI |
                 MAPI_EXPLICIT_PROFILE |
                 MAPI_NEW_SESSION;
       if ( FAILED ( hRes = MAPILogonEx ( 0l,
                                          NULL,
                                          NULL,
                                          ulFlags,
                                          &pLocalSession ) ) )
          goto Quit;
       *pSession = pLocalSession;
    Quit:
    // TODO: Add code to release and free all memory allocated by MAPI.
       return hRes;
    }
    HRESULT ModifyGALRecipient( LPMAPISESSION pSession,
                                ULONG cbRecipEID,
                                LPBYTE lpbRecip )
    {
       HRESULT hRes = S_OK;
       ULONG ulFlags = 0L;
       ULONG ulObjType = 0L;
       ULONG cbEID = 0L;
       LPADRBOOK pAddrBook = NULL;
       LPMAPICONTAINER pGAL = NULL;
       LPMAPICONTAINER pIABRoot = NULL;
       LPMAPITABLE pHTable = NULL;
       LPMAILUSER pRecipient = NULL;
       LPSRowSet pRows = NULL;
       SRestriction sres;
       SPropValue spv;
       LPBYTE lpb = NULL;
       ZeroMemory ( (LPVOID) &sres, sizeof (SRestriction ) );
       // - Call OpenAddressBook from session object
       ulFlags = AB_NO_DIALOG;
       if ( FAILED ( hRes = pSession -> OpenAddressBook ( 0L,
                                                          NULL,
                                                          ulFlags,
                                                          &pAddrBook ) ) )
       goto Quit;
       else
       ulFlags = 0L;
       // - Open the root container of the Address book by calling
       //   IAddrbook::OpenEntry and passing NULL and 0 as the first 2
       //   params.
       ulFlags = MAPI_MODIFY;
       if ( FAILED ( hRes = pAddrBook -> OpenEntry ( NULL,
                                               0L,
                                               &IID_IABContainer,
                                               ulFlags,
                                               &ulObjType,
                                               (LPUNKNOWN *) &pIABRoot ) ))
          goto Quit;
       else
          ulFlags = 0L;
       // Make sure we have a Container object
       if ( MAPI_ABCONT == ulObjType )
       {
          // - Call IMAPIContainer::GetHierarchyTable to open the Hierarchy
          //   table of the root address book container.
          if ( FAILED ( hRes = pIABRoot -> GetHierarchyTable ( ulFlags,
                                                            &pHTable ) ) )
             goto Quit;
          else
             ulFlags = 0l;
          // - Call HrQueryAllRows using a restriction for the only row
          //   that contains DT_GLOBAL as the PR_DISPLAY_TYPE property.
          SizedSPropTagArray ( 2, ptaga ) = {2,PR_DISPLAY_TYPE,PR_ENTRYID};
          sres.rt                          = RES_PROPERTY;
          sres.res.resProperty.relop       = RELOP_EQ;
          sres.res.resProperty.ulPropTag   = PR_DISPLAY_TYPE;
          sres.res.resProperty.lpProp      = &spv;
          spv.ulPropTag = PR_DISPLAY_TYPE;
          spv.Value.l   = DT_GLOBAL;
          if ( FAILED ( hRes = HrQueryAllRows ( pHTable,
                                                (LPSPropTagArray) &ptaga,
                                                &sres,
                                                NULL,
                                                0L,
                                                &pRows ) ) )
             goto Quit;
          else
             ulFlags = 0L;
          // - Call IAddrbook::OpenEntry using the entry id (PR_ENTRYID)
          // from the row returned from HrQueryAllRows to get back an
          // IMAPIContainer object.
          ulFlags = MAPI_MODIFY;
          cbEID = pRows->aRow->lpProps[1].Value.bin.cb;
          lpb = pRows->aRow->lpProps[1].Value.bin.lpb;
          if ( FAILED ( hRes = pAddrBook -> OpenEntry ( cbEID,
                                                        (LPENTRYID)lpb,
                                                         NULL,
                                                         ulFlags,
                                                         &ulObjType,
                                                         (LPUNKNOWN *)&pGAL
                                                         ) ) )
             goto Quit;
          else
             ulFlags = 0L;
          // - Call IMAPIContainer::OpenEntry using the entry id of the
          //   recipient you want to modify.
          ulFlags = MAPI_MODIFY;
          ulObjType = 0;
          if ( FAILED ( hRes = pGAL -> OpenEntry ( cbRecipEID,
                                             (LPENTRYID)lpbRecip,
                                             NULL,
                                             ulFlags,
                                             &ulObjType,
                                             (LPUNKNOWN *)&pRecipient ) ) )
             goto Quit;
           // TODO: Replace the following code with modifications you want to make.
           SPropValue spvNewProp;
           spvNewProp.ulPropTag = PR_BUSINESS_TELEPHONE_NUMBER;
           spvNewProp.Value.lpszA = "(123)456-7890";
           hRes = pRecipient->SetProps(1, &spvNewProp, NULL);
           hRes = pRecipient->SaveChanges(FORCE_SAVE);
           // END TODO
        }
        else
           goto Quit;
    Quit:
    // TODO: Add code to release and free all memory allocated by MAPI
       return hRes;
    }
    HRESULT ModifyRecipient ( )
    {
       HRESULT hRes = S_OK;
       ULONG ulFlags = 0L;
       LPMAPISESSION pSession = NULL;
       LPADRBOOK pAddrBook = NULL;
       ADRPARM AdrParm;
       LPADRLIST pAddrList = NULL;
       ULONG cbEID = 0L;
       LPBYTE lpb = NULL;
       ZeroMemory ( (LPVOID) &AdrParm, sizeof ( ADRPARM ) );
       // set up the adrparm struct for Address
       AdrParm.ulFlags             = DIALOG_MODAL | AB_RESOLVE;
       AdrParm.cDestFields         = 1;
       AdrParm.nDestFieldFocus      = 0;
       AdrParm.lpszNewEntryTitle  = "Whatever";
       AdrParm.lpszDestWellsTitle = "";
       AdrParm.lpszCaption = "Browse Address Book";
       // - Open a MAPI session and pick an Address Entry to modify
       // Logon to MAPI session
       if ( FAILED ( hRes = Logon ( &pSession ) ) )
          goto Quit;
       // Pick a recipient
       if ( FAILED ( hRes = pSession -> OpenAddressBook ( 0L,
                                                          NULL,
                                                          ulFlags,
                                                          &pAddrBook ) ) )
          goto Quit;
       if ( FAILED ( hRes = pAddrBook -> Address ( (ULONG *) &g_hWnd,
                                                   &AdrParm,
                                                   &pAddrList) ) )
          goto Quit;
       cbEID = pAddrList->aEntries[0].rgPropVals[2].Value.bin.cb;
       lpb = pAddrList->aEntries[0].rgPropVals[2].Value.bin.lpb;
       // Modify the recipient
       if ( FAILED ( hRes = ModifyGALRecipient ( pSession, cbEID, lpb ) ) )
          goto Quit;
    Quit:
    // TODO: Add code to release and free all memory allocated by MAPI.
       return hRes;
    }