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

ID: Q235368


The information in this article applies to:


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:

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:


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 kbGrpMsg 
Version           : WINDOWS:1.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 2, 1999