HOWTO: Use Extended MAPI to Access Custom Attributes of Public Folders

ID: Q235368


The information in this article applies to:
  • Extended Messaging Application Programming Interface (MAPI), version 1.0


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:

  • Open the Public Folder.


  • Open the Address Book.


  • Obtain the PR_ADDRESS_BOOK_ENTRYID. This contains the name-service entry identifier of the underlying directory object, which refers to the public folder.


  • Obtain a pointer to the directory object.


  • 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.

#include <windows.h>
#include <edk.h>
#include <stdio.h>

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



REFERENCES

Please refer to the following article in the Microsoft Knowledge Base for a sample code demonstrating using CDO and Extended MAPI to retrieve Custom Attributes of Recipient Objects:

Q178553 INFO: Accessing Custom Attributes of Recipients

Additional query words:

Keywords : kbEDK kbMsg kbVC kbfaq kbGrpMsg
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: December 3, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.