Platform SDK: Active Directory, ADSI, and Directory Services

Win32 Error Codes for ADSI

Standard Win32 error codes are also used to return ADSI error messages. In particular, the ADSI LDAP provider maps all the LDAP error codes to Win32 error codes. The HRESULT values of these error codes are of the 0x8007XXXX format, where the last four hexadecimal digits, XXXX, corresponds to the DWORD values of the appropriate Win32 error code. For example, the ADSI error value 0x80072020 gives the Win32 error value of 0x2020 in hexadecimal or 8224 in decimal.

Most of the Win32 error codes for ADSI are defined in Winerror.h or Lmerr.h. The error values are listed as decimal values in these files. To convert the HRESULT value of an ADSI error code (produced by your application) to the corresponding the Win32 errors DWORD value (defined in the header files above), do the following:

  1. Convert the HRESULT value, hrErr, to a hexadecimal number from the decimal, if starting with a decimal value as you may get from a Visual Basic® application.
  2. Drop the 0x8007 part from hrErr to produce the remainder, dwErr,
  3. Convert dwErr back to a decimal number,
  4. Look dwErr up in Winerror.h.
  5. If not found in Winerror.h, subtract 2100 from dwErr and look up the result in Lmerr.h.

ADSI 2.0 maps the LDAP error codes to a set of Win32 error codes that is different from that used in ADSI for Windows 2000 and DS Client. The differences are listed in the two tables below: