Muokkaa

Jaa


ErrObject.LastDllError Property

Definition

Gets a system error code produced by a call to a dynamic-link library (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

Property Value

A system error code produced by a call to a dynamic-link library (DLL).

Attributes

Examples

The following example shows how you can use the LastDllError property after calling a function in the Windows API. The PrintWindowCoordinates procedure takes a handle to a window and calls the GetWindowRect function. GetWindowRect fills the RECT data structure with the lengths of the sides of the rectangle that make up the window. If you pass an invalid handle, an error occurs, and the error number is available through the LastDllError property.

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

Remarks

The LastDllError property applies only to DLL calls made from Visual Basic code. When such a call is made, the called function usually returns a code indicating success or failure, and the LastDllError property is filled. Check the documentation for the DLL's functions to determine the return values that indicate success or failure. Whenever the failure code is returned, the Visual Basic application should immediately check the LastDllError property. No exception is raised when the LastDllError property is set.

Note

For smart devices, this property always returns zero.

Applies to

See also