The following procedure uses the CreateStoreEntryID method of the IExchangeManageStore interface to log on to a mailbox.
The following sample code shows how to implement the previously listed steps. The sample code is the implementation of the HrMailboxLogon function, located in \BKOFFICE\SAMPLES\EXCHANGE\LIBSRC\MBLOGON\MBLOGON.C.
Note The MBLOGON sample application includes error checking. For clarity, error checking has been removed from this code sample.
// -----------------------------------------------------------------
// HrMailboxLogon() without any error detection.
// -----------------------------------------------------------------
HRESULT HrMailboxLogon(
IN LPMAPISESSION lplhSession, // ptr to MAPI session handle
IN LPMDB lpMDB, // ptr to message store
IN LPTSTR lpszMsgStoreDN, // ptr to server DN
IN LPTSTR lpszMailboxDN, // ptr to mailbox DN
OUT LPEXCHANGEMANAGESTORE *lppXManageStore, // ptr to manage mailbox interface ptr
OUT LPMDB *lppMailboxMDB) // ptr to mailbox message store ptr
{
ULONG cbeid = 0; // count of bytes in entry ID
LPENTRYID lpeid = NULL; // Entry ID of default store
MAPICALL( lpMDB)->QueryInterface( lpMDB, (REFIID) &IID_IExchangeManageStore,
(LPVOID*) lppXManageStore);
MAPICALL( *lppXManageStore)->CreateStoreEntryID(
*lppXManageStore, lpszMsgStoreDN, lpszMailboxDN,
OPENSTORE_USE_ADMIN_PRIVILEGE | OPENSTORE_TAKE_OWNERSHIP,
&cbeid, &lpeid);
MAPICALL( lplhSession)->OpenMsgStore(
lplhSession, 0, cbeid, lpeid, NULL, MDB_NO_DIALOG | MAPI_BEST_ACCESS,
lppMailboxMDB);
MAPIFREEBUFFER( lpeid);
return( NOERROR);
}