Directory Services |
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 data in a per-thread data structure. ADsSetLastError behaves similar to the Win32 function, SetLastError.
VOID ADsSetLastError( DWORD dwErr, LPWSTR pszError, LPWSTR pszProvider );
None.
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 example to examine this operation code
DWORD dwLastError; WCHAR szErrorBuf[MAX_PATH]; WCHAR szNameBuf[MAX_PATH]; // Get extended error value. HRESULT hr_return =S_OK; hr_return = ADsGetLastError( &dwLastError, szErrorBuf, MAX_PATH, szNameBuf, MAX_PATH); if (SUCCEEDED(hr_return)) { wprintf(L"Error Code: %d\n Error Text: %ws\n Provider: %ws\n", dwLastError, szErrorBuf, szNameBuf); }
The previous code exampple produces the following output for the operations error code set above.
Error value: 80072020 Error Text: 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 following output is returned.
Error value: 2020 Error Text: ERROR_DS_OPERATIONS_ERROR Provider: LDAP Provider
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Adshlp.h.
Library: Use ActiveDS.lib.
ADSI Error Codes, ADSI Functions, ADsGetLastError, SetLastError