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

Modifying Properties of a Directory Object via MAPI Interfaces

The following code fragment shows how you can modify properties of directory objects. Mostly, the fragment is similar to the previous one with several minor differences. First of all, an entry is opened with MAPI_MODIFY flag. Second, after getting properties I search through them for a particular one, which stores proxy generator DLL name ( tag 0x810F001E ). Having found one, I modify it and save changes to the object.

#include <MAPIUTIL.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,
                                 MAPI_MODIFY, // Flag required for modification
                                 &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 );

    // Modify proxy generator DLL name
    for ( ULONG ul = 0; ul < ulValues; ul++ ) {

        if ( 0x810F001E == pPropValues[ul].ulPropTag ) {

            // Modify property
            pPropValues[ul].Value.lpszA = "croxygen.dll";

            // Set properties
            hRes = ((IMAPIProp *) lpEntry)->SetProps( 1,
              &pPropValues[ul],
              NULL );
            if ( FAILED( hRes ) )
                throw ( -1 );

            // Save changes
            hRes = ((IMAPIProp *) lpEntry)->SaveChanges( 0 );
            if ( FAILED( hRes ) )
                throw ( -1 );

            break;
        }
    }
 
return ( 0 );
}

After running the above fragment in the debugger you can verify the result either by using Exchange Administrator, or by running previous sample and dump new set of properties to the screen.
 

[ Contents | Home ]

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