ErrObject.LastDllError 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
透過呼叫動態連結函式庫(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 會將一個視窗的 handle 存取並呼叫該 GetWindowRect 函式。
GetWindowRect 將 以構成視窗的矩形邊長填滿 RECT 資料結構。 如果你傳遞無效的 handle ,就會發生錯誤,錯誤編號會透過屬性 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 屬性時不會有例外。
備註
對於智慧裝置,這個特性總是回傳零。