通过


ErrObject.LastDllError 属性

定义

获取由对动态链接库(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

属性值

调用动态链接库(DLL)生成的系统错误代码。

属性

示例

以下示例演示如何在 Windows API 中调用函数后使用该 LastDllError 属性。 该过程 PrintWindowCoordinates 采用窗口句柄并调用 GetWindowRect 函数。 GetWindowRect 用构成窗口的矩形的两侧长度填充 RECT 数据结构。 如果传递无效句柄,将发生错误,并且错误号可通过 LastDllError 属性获得。

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

注解

LastDllError 属性仅适用于从 Visual Basic 代码进行的 DLL 调用。 进行此类调用时,调用的函数通常会返回指示成功或失败的代码,并 LastDllError 填充该属性。 检查 DLL 的函数的文档以确定指示成功或失败的返回值。 每当返回失败代码时,Visual Basic 应用程序应立即检查 LastDllError 该属性。 设置属性时 LastDllError 不会引发异常。

注释

对于智能设备,此属性始终返回零。

适用于

另请参阅