共用方式為


ErrObject.LastDllError 屬性

傳回由動態連結程式庫 (DLL) 的呼叫所產生的系統錯誤碼。唯讀。

命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)

語法

'宣告
Public ReadOnly Property LastDllError As Integer
'用途
Dim instance As ErrObject
Dim value As Integer

value = instance.LastDllError
public int LastDllError { get; }
public:
property int LastDllError {
    int get ();
}
/** @property */
public int get_LastDllError ()
public function get LastDllError () : int

屬性值

傳回由動態連結程式庫 (DLL) 的呼叫所產生的系統錯誤碼。唯讀。

備註

如需詳細資訊,請參閱 Visual Basic 的主題 LastDllError 屬性 (Err 物件)

LastDllError 屬性只會套用到由 Visual Basic 程式碼所進行的 DLL 呼叫。當進行這樣的呼叫時,被呼叫的函式通常會傳回一個表示成功或失敗的代碼,而且會填入 LastDllError 屬性。請查閱 DLL 函式的文件,以判斷指示成功或失敗的傳回值。每當傳回失敗碼時,Visual Basic 應用程式應該立即檢查 LastDllError 屬性。當設定 LastDllError 屬性時,不會引發任何例外狀況。

Note注意事項

LastDllError 屬性需要有 Unmanaged 程式碼使用權限,而這可能會影響它在部分信任狀況下的執行。如需詳細資訊,請參閱 SecurityPermission程式碼存取使用權限

範例

下列範例將示範如何在 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

平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0、1.0

請參閱

參考

ErrObject 類別
ErrObject 成員
Microsoft.VisualBasic 命名空間

其他資源

LastDllError 屬性 (Err 物件)
Err 物件 (Visual Basic)
Declare 陳述式
Description 屬性 (Err 物件)
ErrorToString 函式
HelpContext 屬性 (Err 物件)
HelpFile 屬性 (Err 物件)
Number 屬性 (Err 物件)
Source 屬性 (Err 物件)