Are you a world traveler? ZoneTick is a cool utility that'll help you stay in touch over multiple time zones!
 
Retrieving Properties of a Directory Object via MAPI Interfaces  
Nik Okuntseff  MS Exchange Server Programming 

Retrieving Properties of a Directory Object via MAPI Interfaces

It is possible to access MS Exchange directory objects with MAPI interfaces. Thus, it is an alternative to DAPI - separate, different way of working with directory. I am going to present here two samples - one showing how you can retrieve properties of an Addr-Type object, and another one - how to modify them.

The following sample (Dir/MAPIRead) demonstrates retrieving an Addr-Type object properties:
 
 
#include "CSelfRelPropList.h"
#include "edkutils.h"

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

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

    // Logon to MAPI
    FLAGS flFlags = MAPI_ALLOW_OTHERS |
                                MAPI_EXTENDED;
    hRes = MAPILogonEx( 0, "MS Exchange", NULL, flFlags, &pSession );
    if ( FAILED( hRes ) )
        throw ( -1 );

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

    // Obtain entry id for my Addr-Type object
    ULONG cbeid;
    LPENTRYID peid = NULL;
    hRes = HrCreateDirEntryIdEx( lpAdrBook,
        "/o=Rydex Industries Corporation/ou=DEV/cn=Configuration/cn=Addressing/cn=Address-Types/cn=EDK:i386",
        &cbeid,
        &peid );
     if ( FAILED( hRes ) )
        throw ( -1 );

    // Now open our Addr-Type object
    ULONG           ulObjType = 0;
    LPMAPIPROP      lpEntry   = NULL;
    hRes = lpAdrBook->OpenEntry( cbeid,
                                 peid,
                                 NULL,
                                 0,
                                 &ulObjType,
                                 (LPUNKNOWN*) &lpEntry );
    if ( FAILED( hRes ) )
        throw ( -1 );

    // Now get properties
    ULONG ulValues;
    LPSPropValue pPropValues = NULL;
    hRes = ((IMAPIProp *) lpEntry)->GetProps( NULL,
            0,
            &ulValues,
            &pPropValues );
    if ( FAILED( hRes ) )
        throw ( -1 );

    // Dump them!
    CSelfRelPropList list( ulValues, pPropValues );
    list.Dump();
    return ( 0 );
}

Note that I logon (MAPILogonEx) to MS Exchange server profile after initializing MAPI. Then I open address book and obtain entry ID for my Addr-Type object. Having done that, I open the object (OpenEntry) and obtain all its properties (GetProps). Then I use CSelfRelPropList helper class to dump properties to the screen.

After running the above fragment in the debugger on my Exchange server system, I have seen 25 properties dumped to the screen. In fact, an Addr-Type object contains at least one more, but it is a multiple value property (an array of values). Multiple value properties are not supported by CSelfRelPropList class.

After seeing such dump you will notice right away the difference between DAPI and MAPI approaches. The number of MAPI properties is different from the number of DAPI attributes obtained from the same object. Apparently, two quite different naming conventions are used here. Correlation between MAPI property tags and attribute names is discussed in dedicated place in this book.
 

[ Contents | Home ]

Send comments and suggestions to niko@wrconsulting.com
Copyright © 1997-1998 by Nik Okuntseff