Platform SDK: Active Directory, ADSI, and Directory Services

ADsSetLastError

The ADsSetLastError sets the calling thread's last-error code value. Directory service providers can use this function to set extended errors. The function saves the error information in a "per thread" data structure. ADsSetLastError behaves the same way as the Win32 function, SetLastError.

VOID ADsSetLastError(
  DWORD dwErr, 
  LPWSTR pszError, 
  LPWSTR pszProviderName 
);

Parameters

dwErr
[in] The error code that occurred. If this is an error defined by Windows, pszError is ignored. If this is ERROR_EXTENDED_ERROR, it indicates the provider has a network-specific error to report.
pszError
[in] String describing the network-specific error.
pszProviderName
[in] String naming the ADSI provider raising the error.

Return Values

None.

Remarks

In a custom implementation of an ADSI provider, for example, an LDAP provider, you can set an operation error message as follows:

ADsSetLastError(HRESULT_FROM_WIN32(ERROR_DS_OPERATIONS_ERROR),
                L"ERROR_DS_OPERATIONS_ERROR",
                L"LDAP Provider");

The user can use the following code snippet to examine this operation code:

DWORD dwErr;
WCHAR szErr[256];
WCHAR szProv[256];
HRESULT hrGet = ADsGetLastError(dwErr, szErr, szProv);
printf("Error value: %x\n    Message: %ws\n    Provider: %ws\n",
        dwErr, szErr, szProv);

The above code segment will produce the following output for the operations error code set above:

Error value: 80072020
    Message: ERROR_DS_OPERATIONS_ERROR
    Provider: LDAP Provider

If you use ERROR_DS_OPERATIONS_ERROR without invoking the HRESULT_FROM_WIN32 macro when setting the error, the user will get the following output instead:

Error value: 2020
    Message: ERROR_DS_OPERATIONS_ERROR
    Provider: LDAP Provider

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Adshlp.h.
  Library: Included as a resource in ActiveDs.dll.

See Also

ADSI Error Codes, ADSI Functions, ADsGetLastError, SetLastError