How to: Obtain a Contact Message Given a Contacts Address Book Entry

How to: Obtain a Contact Message Given a Contacts Address Book Entry

This topic contains an example in C++, HrOpenContact, that shows how to use the CONTAB_ENTRYID structure that identifies an entry in a Contacts Address Book to obtain the associated MAPI Contact message.

HrOpenContact has the following parameters:

  • lpSession is an input parameter representing the current session. LPMAPISESSION is defined in the MAPI header file mapix.h as a pointer to IMAPISession.
  • cbEntryID is an input parameter representing the size of the entry identifier associated with lpEntryID.
  • lpEntryID is an input parameter representing a pointer to the entry identifier of an entry in a Contact Address Book.
  • ulFlags is an input parameter representing a bitmask containing object access flags to the MAPI Contact message.
  • lpContactMessage is an output parameter representing a pointer to the MAPI Contact message.

To open the underlying MAPI Contact message, HrOpenContact first casts lpEntryID to a pointer to CONTAB_ENTRYID. It then calls IMAPISession::OpenEntry to obtain the MAPI Contact message, passing as parameters the cbeid and abeid fields of the entry in the Contacts Address Book that identify respectively the size of the entry identifier and the entry identifier of the MAPI Contact message.

  HRESULT HrOpenContact(
    LPMAPISESSION lpSession,
    ULONG cbEntryID,
    LPENTRYID lpEntryID,
    ULONG ulFlags,
    LPMESSAGE* lpContactMessage)
{
    ULONG ulObjType = NULL;
if (sizeof(CONTAB_ENTRYID) > cbEntryID) return MAPI_E_INVALID_PARAMETER;
LPCONTAB_ENTRYID lpContabEID = (LPCONTAB_ENTRYID) lpEntryID;

HRESULT hRes = lpSession->OpenEntry(
    lpContabEID->cbeid,
    (LPENTRYID) lpContabEID->abeid,
    NULL,
    ulFlags,
    &ulObjType,
    (LPUNKNOWN*) lpContactMessage);

return hRes;

}

See Also

IMAPISession::OpenEntry