ErrObject.LastDllError Propriété

Définition

Obtient un code d’erreur système produit par un appel à une bibliothèque de liens dynamiques (DLL).

public:
 property int LastDllError { int get(); };
public int LastDllError { get; }
public int LastDllError { [System.Security.SecurityCritical] get; }
member this.LastDllError : int
[<get: System.Security.SecurityCritical>]
member this.LastDllError : int
Public ReadOnly Property LastDllError As Integer

Valeur de propriété

Code d’erreur système généré par un appel à une bibliothèque de liens dynamiques (DLL).

Attributs

Exemples

L’exemple suivant montre comment utiliser la LastDllError propriété après l’appel d’une fonction dans l’API Windows. La PrintWindowCoordinates procédure prend un handle dans une fenêtre et appelle la GetWindowRect fonction. GetWindowRect remplit la structure de données RECT avec les longueurs des côtés du rectangle qui composent la fenêtre. Si vous transmettez un handle non valide, une erreur se produit et le numéro d’erreur est disponible via la LastDllError propriété .

Declare Function GetWindowRect Lib "user32" (
    ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer

Public Structure RECT
    Public Left As Integer
    Public Top As Integer
    Public Right As Integer
    Public Bottom As Integer
End Structure

Const ERROR_INVALID_WINDOW_HANDLE As Long = 1400
Const ERROR_INVALID_WINDOW_HANDLE_DESCR As String = 
    "Invalid window handle."
Private Sub PrintWindowCoordinates(ByVal hwnd As Integer)
' Prints left, right, top, and bottom positions
' of a window in pixels.

  Dim rectWindow As RECT

  ' Pass in window handle and empty the data structure.
  ' If function returns 0, an error occurred.
  If GetWindowRect(hwnd, rectWindow) = 0 Then
      ' Check LastDllError and display a dialog box if the error
      ' occurred because an invalid handle was passed.
      If Err.LastDllError = ERROR_INVALID_WINDOW_HANDLE Then
          MsgBox(ERROR_INVALID_WINDOW_HANDLE_DESCR, Title:="Error!")
      End If
  Else
      Debug.Print(rectWindow.Bottom)
      Debug.Print(rectWindow.Left)
      Debug.Print(rectWindow.Right)
      Debug.Print(rectWindow.Top)
  End If
End Sub

Remarques

La LastDllError propriété s’applique uniquement aux appels DLL effectués à partir de code Visual Basic. Lorsqu’un tel appel est effectué, la fonction appelée retourne généralement un code indiquant la réussite ou l’échec, et la LastDllError propriété est remplie. Consultez la documentation relative aux fonctions de la DLL pour déterminer les valeurs de retour qui indiquent la réussite ou l’échec. Chaque fois que le code d’échec est retourné, l’application Visual Basic doit immédiatement case activée la LastDllError propriété. Aucune exception n’est levée lorsque la LastDllError propriété est définie.

Notes

Pour les appareils intelligents, cette propriété retourne toujours zéro.

S’applique à

Voir aussi