How To Restrict Address Book Entries with PR_EMS_AB_PROXY_ADDRESSES (302805)



The information in this article applies to:

  • Microsoft Extended Messaging Application Programming Interface (MAPI)

This article was previously published under Q302805

SUMMARY

This article contains an Extended MAPI code sample that demonstrates how to restrict address book entries by using the multi-valued PR_EMS_AB_PROXY_ADDRESSES property.

MORE INFORMATION

Multi-valued properties can be used in property restrictions if the service provider that is implementing the table supports them. If supported, multi-valued property tags can be used anywhere that single-valued property tags can be used.

Sample Code

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: To run the sample, follow these steps:
  1. With the Win32 Console Application AppWizard, create a new Simple project and name it Restrictmultivalued.
  2. Open Restrictmultivalued.cpp. Paste the following code after
    #include "stdafx.h"
    						
    and replace the main function:
    #include <windows.h>
    #include <mapix.h>
    #include <addrlkup.h>
    #include <mapiutil.h>
    #include <edk.h>
    #include <stdio.h>
    
    void main()
    {
        HRESULT                 hr = S_OK;
        LPMAPISESSION           lpSession = NULL;
        LPADRBOOK               lpAddrbk = NULL;
        LPMAPICONTAINER         lpGAL = NULL;
        ULONG                   ulObjType = NULL;
        ULONG                   cbeid = 0L;
        LPENTRYID               lpeid = NULL;
        LPSRowSet               pRows = NULL;
        ULONG                   cRows    = 0L;
        LPMAPITABLE             lpContentsTable = NULL; 
        ULONG                   i;
        
        enum {ePR_ENTRYID, ePR_DISPLAY_NAME, NUM_COLS};
        
        SizedSPropTagArray( NUM_COLS, sptCols ) = { NUM_COLS,
                                                    PR_ENTRYID,
                                                    PR_DISPLAY_NAME};
        
        // Build a multi-valued restrict array.
        SLPSTRArray mvArray;
        // Replace with array of proxy addresses of a 
        // recipient you want to search in address book.
        LPSTR lppsz[2] = 
            {"X400:c=us;a= ;p=First Organizati;o=Exchange;s=Doe;g=John;",
            "SMTP:JohnDoe@xyz.com"};
        mvArray.cValues = 2;
        mvArray.lppszA = lppsz;
        
        // Initialize MAPI Subsystem.
        hr = MAPIInitialize(NULL);
        if (S_OK != hr) return;
        
        // Log on to MAPI.
        hr = MAPILogonEx(0,
                         NULL,
                         NULL,
                         MAPI_LOGON_UI,
                         &lpSession);
        if (FAILED(hr)) goto UnInit;
        
        hr = lpSession->OpenAddressBook(0,
                                        NULL,
                                        0,
                                        &lpAddrbk);
        if (FAILED(hr)) goto Cleanup0;
        
        
        //Open GAL.
        hr = HrFindExchangeGlobalAddressList(lpAddrbk,
                                             &cbeid,
                                             &lpeid); 
        
        if (FAILED(hr)) goto Quit;
        
        hr = lpAddrbk->OpenEntry((ULONG) cbeid,
                                 (LPENTRYID) lpeid,
                                 NULL,
                                 MAPI_BEST_ACCESS,
                                 &ulObjType,
                                 (LPUNKNOWN *)&lpGAL);
        
        if (FAILED(hr)) goto Quit;
        
        if (ulObjType != MAPI_ABCONT )
            goto Quit;
        
        hr = lpGAL->GetContentsTable(0L, 
                                     &lpContentsTable);
        if (FAILED(hr)) goto Quit;
        
        hr = lpContentsTable->SetColumns((LPSPropTagArray)&sptCols,
                                         TBL_BATCH);
        if (FAILED(hr)) goto Quit;
        
        hr = lpContentsTable->GetRowCount(0, 
                                          &cRows);
        if (FAILED(hr)) goto Quit;
        
        printf("Total number of Rows: %d\n", cRows);
        
        // Restriction on PR_EMS_AB_PROXY_ADDRESSES.
        
        SRestriction srName;
        SPropValue spv;
        srName.rt = RES_PROPERTY;
        srName.res.resProperty.relop = RELOP_EQ;
        srName.res.resProperty.ulPropTag = PR_EMS_AB_PROXY_ADDRESSES;    
        srName.res.resProperty.lpProp = &spv;
        spv.ulPropTag = PR_EMS_AB_PROXY_ADDRESSES; 
        spv.Value.MVszA = mvArray;
        
        hr = HrQueryAllRows(lpContentsTable,
                            (LPSPropTagArray) &sptCols,
                            &srName,//restriction
                            NULL,//sort order
                            0,
                            &pRows);
        if (FAILED(hr)) goto Quit;
        
        for (i = 0; i < pRows -> cRows; i++)
        {
            if (PR_DISPLAY_NAME == 
                pRows -> aRow[i].lpProps[ePR_DISPLAY_NAME].ulPropTag)
            {
                printf("Displayname: '%s'\n",
                    pRows -> aRow[i].lpProps[ePR_DISPLAY_NAME].Value.lpszA);
            }
        }
        
    Quit:
        if ( lpGAL )
        {
            lpGAL -> Release ( );
            lpGAL = NULL;
        }
        
        if ( lpContentsTable )
        {
            lpContentsTable -> Release ( );
            lpContentsTable = NULL;
        }
        
        if ( pRows ) FreeProws(pRows);
        
    Cleanup0:
        
        if ( lpAddrbk ) lpAddrbk->Release();
        
        lpSession->Logoff(0, 0, 0);
        if ( lpSession ) lpSession->Release();
        
    UnInit:
        MAPIUninitialize();
    } 
    					
  3. Replace the following with an array of proxy addresses of a recipient that you want to search.
    lppsz[2]
    					
  4. On the Project menu, click Settings, and then click the Link tab. In Object/Library Modules, add the following:
    • Exchsdk.lib
    • Edkutils.lib
    • Mapi32.lib
    • Msvcrt.lib
    • Kernel32.lib

  5. Compile and build the project.

Modification Type:MinorLast Reviewed:8/24/2005
Keywords:kbhowto kbMsg KB302805