Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The ADsSetLastError sets the last-error code value for the calling thread. Directory service providers can use this function to set extended errors. The function saves the error data in a per-thread data structure. ADsSetLastError operates similar to the SetLastError function.
Syntax
VOID ADsSetLastError(
[in] DWORD dwErr,
[in] LPCWSTR pszError,
[in] LPCWSTR pszProvider
);
Parameters
[in] dwErr
Type: DWORD
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.
[in] pszError
Type: LPWSTR
The null-terminated Unicode string that describes the network-specific error.
[in] pszProvider
Type: LPWSTR
The null-terminated Unicode string that names the ADSI provider that raised the error.
Return value
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 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 example 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
Requirements
| Requirement | Value |
|---|---|
| Minimum supported client | Windows Vista |
| Minimum supported server | Windows Server 2008 |
| Target Platform | Windows |
| Header | adshlp.h |
| Library | Activeds.lib |
| DLL | Activeds.dll |