Microsoft KB Archive/302805

= How To Restrict Address Book Entries with PR_EMS_AB_PROXY_ADDRESSES =

Article ID: 302805

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface

-



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:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

To run the sample, follow these steps:  With the Win32 Console Application AppWizard, create a new Simple project and name it Restrictmultivalued.  Open Restrictmultivalued.cpp. Paste the following code after and replace the main function:
 * 1) include &quot;stdafx.h&quot;
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include 

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] = {&quot;X400:c=us;a= ;p=First Organizati;o=Exchange;s=Doe;g=John;&quot;, &quot;SMTP:JohnDoe@xyz.com&quot;}; 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(&quot;Total number of Rows: %d\n&quot;, 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(&quot;Displayname: '%s'\n&quot;,                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; }                      Replace the following with an array of proxy addresses of a recipient that you want to search. lppsz[2]  On the Project menu, click Settings, and then click the Link tab. In Object/Library Modules, add the following: <ul> Exchsdk.lib</li> Edkutils.lib</li> Mapi32.lib</li> Msvcrt.lib</li> Kernel32.lib</li></ul>

</li> Compile and build the project.</li></ol>

Additional query words: restriction multivalued

Keywords: kbhowto kbmsg KB302805

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.