![]() |
|
||||
Directory API - Starting and Ending a DAPI SessionStarting and Ending a DAPI SessionThere are a couple of functions that you would perhaps see quite often: they are DAPIStart and DAPIEnd. The first one initializes a DAPI session and the last one terminates it. When you initialize DAPI session with DAPIStart, a handle is returned. This handle is required as a parameter to a few other DAPI functions (such as DAPIRead). The following simple code fragment (Dir/DAPIStartEnd sample) illustrates how to use this pair of functions.#include <afxwin.h>
int main( void )
// Initialize DAPI
printf( "Error!..\n" );
// We have DAPI session. We can use it here... // Terminate DAPI session
DAPIStart creates a DAPI session, and DAPIEnd terminates it. If you run the above fragment in the debugger, there are a few things that you could notice:
Starting a DAPI Session on a Remote MachineYou may easily access a remote Exchange server directory. This is accomplished by specifying the directory service agent (DSA) name in the DAPI_PARMS structure before calling the DAPIStart:.parms.pszDSAName = "MIG"; // Exchange server computer name If you don't specify DSA name the DAPIStart will attempt to use the local one. If local one is not found, the first one found on the network will be used. There are two important potential points of failure when communicating to a remote DSA. Registry
"No Auto Naming rule was defined for %1. The default rule %2 will be used if no value for %1 is specified in the import file. An Auto Naming rule can be defined using the Options menu item in the Exchange Administrator program." A clean machine does not have this key. You'll need to either set up the Exchange Administrator on such machine (the setup program takes care of the registry), or import the registry data (use Import Registry File / Export Registry File menu options of your regedit program). The following two REG_SZ values are needed for DAPI: ANGAutotextFormat and DNGAutotextFormat. Set first to "%First%1Last" and second to %First %Last". Also, you'll need a REG_DWORD value named AdminLangID set up to 0x409 as described in MSDN Library article "INFO: Items Required to Use DAPI". However, I was able to use DAPI without it. I have provided the DAPI.reg file in the Bin directory in my samples. This file contains all three entries. If you double-click it when using Windows NT Explorer, it will import them into appropriate place in the registry. DLLs
Right Security Context
"Could not bind to the Microsoft Exchange Directory server %2. %1". This is an insufficient security permissions error.
Using DAPI Calls in a Windows NT serviceYou may want to use DAPI in your Windows NT service application. The same two problems (registry and correct security context) apply here as well.Registry
Right Security Context
Performance Drawback of DAPIStartOne thing that you should consider when deciding whether to use DAPI or not is the performance drawback of the DAPIStart function. As I have mentioned, it may take 10 seconds to complete. Obviously, it is not a good sign. The other thing that you may discover is the need to call DAPIStart/DAPIEnd pairs many times if you want to modify objects in different containers with DAPIWrite. This is because DAPIWrite requires proper initialization of DAPI_PARMS pszContainer member. This initialization is done during the DAPIStart call. On a good sign, only the first call to the DAPIStart is so time-consuming. Subsequent calls to DAPIEnd and DAPIStart again go much faster.An alternative here is to use MAPI for access to directory objects.
I am having a few examples later in this chapter. However, this requires
logging on to a MAPI profile with MAPILogonEx function. This profile may
not be available. For example, this may not be appropriate for writing
setup programs for end users.
|