Microsoft KB Archive/235368

= How To Use Extended MAPI to Access Custom Attributes of Public Folders =

Article ID: 235368

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface

-



This article was previously published under Q235368



SUMMARY
The purpose of this article is to demonstrate a method to access the value in a Custom Attribute of an Exchange Server Public Folder.



MORE INFORMATION
Custom Attributes are stored in the Exchange Server PR_EMS_AB_EXTENSION_ATTRIBUTE_X properties. These properties are general attributes available to application developers or administrators and are valid only when reading from the Microsoft Exchange Server address book.

To access a custom attribute on a public folder, follow these steps:
 * 1) Open the Public Folder.
 * 2) Open the Address Book.
 * 3) Obtain the PR_ADDRESS_BOOK_ENTRYID. This contains the name-service entry identifier of the underlying directory object, which refers to the public folder.
 * 4) Obtain a pointer to the directory object.
 * 5) Use either HrGetOneProp or GetProps to obtain the custom attribute.

The code sample below suggests a method to access Custom Attribute 1 of a public folder.
 * 1) include 
 * 2) include 
 * 3) include 

void main {   HRESULT         hr = NULL; LPMAPISESSION      lpSession = NULL; LPMDB          lpPubStore = NULL; LPMAPIFOLDER       lpPubFolders = NULL; LPMAPIFOLDER       lpMyFolder = NULL; LPADRBOOK                    lpAdrBook = NULL; LPMAPIPROP     lpEntry = NULL; ULONG          ulObjType = 0; LPSPropValue       lpspvFolderAddBkEID = NULL; LPSPropValue       pProp;

hr = MAPIInitialize(NULL); if (S_OK != hr) return;

hr = MAPILogonEx(0,           NULL,            NULL,            MAPI_LOGON_UI | MAPI_NEW_SESSION | MAPI_EXTENDED | MAPI_ALLOW_OTHERS,             &lpSession); if (FAILED(hr)) goto UnInit;

// open Public Folder/All Public Folders/MyContact folder hr = HrOpenExchangePublicStore(lpSession, &lpPubStore); if (FAILED(hr)) goto Cleanup0;

hr = HrOpenExchangePublicFolders(lpPubStore, &lpPubFolders); if (FAILED(hr)) goto Cleanup0; hr = HrMAPIOpenSubfolderEx(lpPubFolders, '\\',               "\\MyContact", &lpMyFolder); if (FAILED(hr)) goto Cleanup0;

hr = lpSession->OpenAddressBook(0, 0, 0, &lpAdrBook); if (FAILED(hr)) goto Cleanup0;

hr = HrGetOneProp((LPMAPIPROP)lpMyFolder, PR_ADDRESS_BOOK_ENTRYID, &lpspvFolderAddBkEID); if (FAILED(hr)) goto Cleanup0;

hr = lpAdrBook->OpenEntry(lpspvFolderAddBkEID->Value.bin.cb,           (LPENTRYID)lpspvFolderAddBkEID->Value.bin.lpb,            NULL,            MAPI_MODIFY | MAPI_DEFERRED_ERRORS,            &ulObjType,             (LPUNKNOWN FAR *) &lpEntry); if (FAILED(hr)) goto Cleanup0; hr = HrGetOneProp((LPMAPIPROP)lpEntry, PR_EMS_AB_EXTENSION_ATTRIBUTE_1, &pProp); if (FAILED(hr)) goto Cleanup0;

if(SUCCEEDED(hr)) MessageBox(NULL, pProp->Value.lpszA, "Custom Attribute 1", MB_OK);

Cleanup0: if (lpEntry) lpEntry->Release; if (lpAdrBook) lpAdrBook->Release; if (lpMyFolder) lpMyFolder->Release; if (lpPubFolders) lpPubFolders->Release; if (lpPubStore) lpPubStore->Release;

lpSession->Logoff(0,MAPI_LOGOFF_UI,0); lpSession->Release;

UnInit: MAPIUninitialize; } NOTE: This code sample has been compiled using the "Ignore all default libraries" option on the Link tab of the project Settings dialog box. The following libraries must also be used:
 * Edkguid.lib
 * Addrlkup.lib
 * Edkutils.lib
 * Edkdebug.lib
 * Version.lib
 * Edkmapi.lib
 * Msvcrt.lib
 * Mapi32.lib
 * User32.lib
 * Advapi32.lib
 * Kernel32.lib

