ErrObject.LastDllError プロパティ
アセンブリ: Microsoft.VisualBasic (microsoft.visualbasic.dll 内)


詳細については、Visual Basic のトピック「LastDllError プロパティ (Err オブジェクト)」を参照してください。
LastDllError プロパティは、Visual Basic コードから実行された DLL 呼び出しにのみ適用されます。そのような呼び出しが実行された場合、通常は、呼び出された関数が成功または失敗を示すコードを返し、LastDllError プロパティに値が設定されます。成功または失敗を示す戻り値の識別の詳細については、DLL の関数のドキュメントを参照してください。失敗を表すコードが返されると、Visual Basic アプリケーションはすぐに LastDllError プロパティを確認します。LastDllError プロパティが設定されている場合、例外は発生しません。
![]() |
---|
LastDllError プロパティには、アンマネージ コード アクセス許可が必要です。ただし、部分的に信頼されている状況でこの許可を使用すると、プログラムの実行に影響を及ぼす場合があります。詳細については、SecurityPermission、コード アクセス許可 の各トピックを参照してください。 |

Windows API で関数を呼び出した後で LastDllError プロパティを使用する方法を次の例に示します。PrintWindowCoordinates プロシージャは、ウィンドウのハンドルを受け取り、GetWindowRect 関数を呼び出します。GetWindowRect は、ウィンドウを構成する矩形の幅と同じ長さのデータを RECT データ構造体に格納します。無効なハンドルを渡すと、エラーが発生します。このエラー番号は LastDllError プロパティで使用できます。
Declare Function GetWindowRect Lib "user32" _ (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer <br /><span space="preserve">...</span><br /> Public Structure RECT Public Left As Integer Public Top As Integer Public Right As Integer Public Bottom As Integer End Structure <br /><span space="preserve">...</span><br /> 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からErrObject.LastDllError プロパティを検索する場合は、下記のリンクをクリックしてください。

- ErrObject.LastDllError プロパティのページへのリンク