If you are going to use the Active Directory Service Interface (ADSI) in Delphi, the first thing you will need is the typelibrary (TLB). This TLB is in the windows\system32 folder and has the name activeds.tlb.

We can import this tlb in Delphi (the procedure differs somewhat, depending on the Delphi version), but there are quite some problems with the resulting pas file of this import:

  • Ugly and non meaningfull names such as __MIDL___MIDL_itf_ads_0000_0000_001.
  • Record sizes are sometimes (read: usually) wrong due to alignment errors.
  • Some Interfaces have wrong declarations resulting in Access Violations or just hard to use (eg using var for input parameters).
  • Delphi works with Typed Pointer but since it has no clue on the proper name it uses PUserTypexx (eg PUserType1 = ^_ADS_CASEIGNORE_LIST). It’s hard to recognise later on what the real type is.

A version of the imported tlb is also in the Jedi Apilib (JwaAdsTLB) and basically it had the same errors. Because I was wondering how this would work in c++ I checked the SDK and found the header file Iads.h.

If you open Iads.h you can see that this header file is generated by the MIDL compiler from a file called ads.odl with the following settings:

/* Compiler settings for ads.odl:
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555

Zp8 means alignment on 8 byte boundaries which Delphi does not seem to support.

I decided to convert Iads.h and merge this with the imported tlb.

Here are some examples of the corrections:

Imported Tlb:


Imported Tlb:


If you are looking for the file: I commited it to the trunk as JwaAdsTLB.pas.