Hello Gurus,

I'm trying to write a program that will allow user to do a search on the Global Address List (GAL)
on a particular user and retrieve a list emails matching that user. I know how to locate and open GAL:

- Start a MAPI session.
- Open the address book by using IMAPISession::OpenAddressBook.
- Locate GAL by calling HrFindExchangeGlobalAddressList and using the LPADRBOOK pointer from previous step.
- Open GAL by using the IMAPISession::OpenEntry method.


#include <afxwin.h>
#include <mapix.h>
#include <addrlkup.h>

int main()
{
HRESULT hRes;
LPMAPISESSION pSession = NULL;

// Initialize MAPI
hRes = MAPIInitialize(NULL);
if (FAILED(hRes)) throw -1;

// Obtain MAPI session
hRes = MAPILogonEx(0, // Handle to parent window
"MS Exchange Settings", // Profile name
NULL, // Password
MAPI_NEW_SESSION |
MAPI_EXTENDED |
MAPI_LOGON_UI, // Logon flags
&pSession); // Resulting MAPI session
if (FAILED(hRes)) throw -1;

// Open the address book
LPADRBOOK pAdrBook = NULL;
hRes = pSession->OpenAddressBook(0, 0, MAPI_ACCESS_MODIFY, &pAdrBook);
if (FAILED(hRes)) throw -1;

// Locate GAL
ULONG cbGalEid = 0; // Count of bytes in GAL entry ID
LPENTRYID pGalEid = NULL; // GAL entry ID
hRes = HrFindExchangeGlobalAddressList(pAdrBook, &cbGalEid, &pGalEid);
if (FAILED(hRes)) throw -1;

// Open GAL
ULONG ulObjType = 0;
LPUNKNOWN pGal = NULL;
hRes = pSession->OpenEntry(cbGalEid, // Count of bytes in entry ID
pGalEid, // Entry ID
NULL, // Pointer to IID we want
MAPI_MODIFY, // Access flags
&ulObjType, // Object type
&pGal); // Resulting pointer
if (FAILED(hRes)) throw -1;

// Display success string.
MessageBox(NULL, "Successfully opened GAL. Now exiting...", "Success",
MB_OK | MB_ICONINFORMATION);

//----------------------------
// NOT SURE WHAT TO DO NEXT???
//----------------------------

return 0;
}

But I'm not sure how to perform a search on the GAL with a query and get a list of matching emails?
If you can help I would really appreciate it. Thank you!

Marci Sarwan (marci_sarwan@yahoo.com)

PS: I'm a novice when it comes to MAPI so if it's not too much trouble can you please provide some sample code? Thank you very much!