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 with DAPIRead  
Nik Okuntseff  MS Exchange Server Programming 

Retrieving Properties of a Directory Object with DAPIRead

Let me extend the example in previous subsection with a call to DAPIRead. DAPIRead function obtains properties of an individual directory object. Suppose I want to retrieve properties of an Addr-Type object, which had been installed with the sample gateway installation. You may take a look at this object in your configuration hierarchy under Addressing / E-Mail Address Generators. Here is this sample code (Dir/DAPIRead sample):

#include <afxwin.h>
#include <dapi.h>

int main( void )
{
    DAPI_PARMS parms = {0};
    parms.dwDAPISignature = DAPI_SIGNATURE;
 
    PDAPI_EVENT pDAPIEvent = NULL;
    DAPI_HANDLE hDAPISession = NULL;

    // Initialize DAPI
    pDAPIEvent = ::DAPIStart( &hDAPISession, &parms );
    if ( pDAPIEvent ) {

        printf( "Error!..\n" );
        return ( -1 );
    }

    // We have DAPI session. Use it now for read.
    DAPI_ENTRY * pdeValues = NULL;
    DAPI_ENTRY * pdeAttributes = NULL;
    pDAPIEvent = ::DAPIRead( hDAPISession,
        DAPI_READ_ALL_ATTRIBUTES,
        "/o=Rydex Industries Corporation/ou=DEV/cn=Configuration/cn=Addressing/cn=Address-Types/cn=EDK:i386",
        NULL,
        &pdeValues,
        &pdeAttributes );
 
    if ( pDAPIEvent ) {

        printf( "Error!..\n" );
        return ( -1 );
    }

    // Deallocate memory
    if ( pdeValues )
        ::DAPIFreeMemory( pdeValues );
    if ( pdeAttributes )
        ::DAPIFreeMemory( pdeAttributes );

    // Terminate DAPI session
    ::DAPIEnd( &hDAPISession );
    return ( 0 );
}

Notice that I have passed DAPI session in first parameter to DAPIRead, and full name of my Addr-Type object in third parameter. You may easily obtain this name if you start Exchange Administrator in raw mode, obtain a list of raw properties for the object ("Raw Properties" on "File" menu) and then look into its Obj-Dist-Name property. You may even cut and paste this long string from Exchange Administrator into your code. Obviously, some components of this long string will be different in your particular case.

When you step over the DAPIRead function in the above example in the debugger, you should see that pdeValues and pdeAttributes have been assigned new values (I assume the function call is successful). You may expand the pointers in the debugger's watch window and observe components of the structures.

Notice two calls to DAPIFreeMemory before I call DAPIEnd. This is what Microsoft recommends in the description of the DAPIRead function.
 

[ Contents | Home ]

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