uses DAPI;
procedure
TForm1.Button1Click(Sender: TObject);
var
DSession:DAPI_HANDLE; (* Points to the handle of the
directory operation session *)
DAPIParms:DAPI_PARMS; (* Points to a DAPI_PARMS
structure containing the directory interface object. *)
pDAPIEvent:PDAPI_EVENT; (* The DAPI_EVENT structure
contains information about errors that are encountered during the execution of a
DAPI function *)
pValues, (* Points to the address where the pointer to a DAPI_ENTRY
structure containing the values read from the DIT entry is stored *)
pAttributes: PDAPI_ENTRY; (* Points to the address where a DAPI_ENTRY
structure containing the names of the attributes read from the DIT is stored. *)
begin
DAPIParms.dwDAPISignature:=DAPI_SIGNATURE;
DAPIParms.dwFlags := DAPI_EVENT_ALL;
// Initialize DAPI
pDAPIEvent:=DAPIStart(@DSession,@DAPIParms);
if Assigned(pDAPIEvent) then
ShowMessage('Error')
else
// We have DAPI
session. Use it now for read.
begin
pValue:=nil;
pAttributes:=nil;
pDAPIEvent:=DAPIRead(
DSession,
DAPI_READ_ALL_ATTRIBUTES,
'/o=IMIBO Corporation/ou=DEV/cn=Recipients/cn=Administrator',
nil,
@pValue,
@pAttributes);
if Assigned(pDAPIEvent) then
ShowMessage('Error')
else
begin
// Process pAttributes and
pValue
...
...
end;
// Deallocate memory
if Assigned(pValue) then DAPIFreeMemory(pValue);
if Assigned(pAttributes) then DAPIFreeMemory(pAttributes);
// Terminate DAPI session
DAPIEnd(@DSession);
end;
end;
Notice that I have passed DAPI session in first parameter to DAPIRead, and full name of Mailbox 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 pValues and pAttributes 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.