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 會接受視窗的句柄,並呼叫 函式 GetWindowRectGetWindowRect 使用構成視窗之矩形側邊的長度填滿 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 不會引發例外狀況。

注意

對於智慧型手機裝置,此屬性一律會傳回零。

適用於

另請參閱