Funzione ADsGetLastError (adshlp.h)

La funzione ADsGetLastError recupera il valore del codice dell'ultimo errore del thread chiamante.

Sintassi

HRESULT ADsGetLastError(
  [out] LPDWORD lpError,
  [out] LPWSTR  lpErrorBuf,
  [in]  DWORD   dwErrorBufLen,
  [out] LPWSTR  lpNameBuf,
  [in]  DWORD   dwNameBufLen
);

Parametri

[out] lpError

Tipo: LPDWORD

Puntatore al percorso che riceve il codice di errore.

[out] lpErrorBuf

Tipo: LPWSTR

Puntatore al percorso che riceve la stringa Unicode con terminazione null che descrive l'errore.

[in] dwErrorBufLen

Tipo: DWORD

Dimensioni, in caratteri, del buffer lpErrorBuf . Se il buffer è troppo piccolo per ricevere la stringa di errore, la stringa viene troncata, ma ancora terminata null. È consigliabile un buffer di almeno 256 byte.

[out] lpNameBuf

Tipo: LPWSTR

Puntatore al percorso che riceve la stringa Unicode con terminazione null che descrive il nome del provider che ha generato l'errore.

[in] dwNameBufLen

Tipo: DWORD

Dimensioni, in caratteri, del buffer lpNameBuf . Se il buffer è troppo piccolo per ricevere il nome del provider, la stringa viene troncata, ma ancora terminata null.

Valore restituito

Tipo: HRESULT

Questo metodo supporta valori restituiti standard, nonché i seguenti.

Commenti

Gli errori ADSI rientrano in due tipi in base ai valori del codice della struttura. I codici di errore ADSI standard hanno un valore di codice della struttura di 0x5 e i codici di errore ADSI estesi presuppongono che FACILITY_WIN32. I valori di errore dei codici di errore ADSI standard e estesi sono rispettivamente i formati 0x80005xxx e 0x8007xxxx. Usare la macro HRESULT_FACILITY(hr) per determinare il tipo di errore ADSI.

Nota Il provider WinNT ADSI non supporta ADsGetLastError.
 
Nell'esempio di codice seguente viene illustrato come ottenere codici di errore Win32 e le relative descrizioni usando ADsGetLastError.
if (FAILED(hr))
{
    wprintf(L"An error occurred.\n  HRESULT: %x\n",hr);
    // If facility is Win32, get the Win32 error 
    if (HRESULT_FACILITY(hr)==FACILITY_WIN32)
    {
        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);
        }
    }
}

Se hr è 80071392, l'esempio di codice restituisce quanto segue.

An error occurred.
    HRESULT: 80071392
    Error Code: 8305
    Error Text: 00002071: UpdErr: DSID-030502F1, problem 6005 (ENTRY_EXISTS), data 0
    Provider: LDAP Provider
Nota Il provider WinNT ADSI non supporta ADsGetLastError.
 

Requisiti

Requisito Valore
Client minimo supportato Windows Vista
Server minimo supportato Windows Server 2008
Piattaforma di destinazione Windows
Intestazione adshlp.h
Libreria Activeds.lib
DLL Activeds.dll; AdsLdpc.dll

Vedi anche

Codici di errore ADSI

Funzioni ADSI

ADsSetLastError

Getlasterror