次の方法で共有


Marshal.GetHRForLastWin32Error メソッド

Marshal を使用して実行した Win32 コードが原因の最終エラーに対応する HRESULT を返します。

Public Shared Function GetHRForLastWin32Error() As Integer
[C#]
public static int GetHRForLastWin32Error();
[C++]
public: static int GetHRForLastWin32Error();
[JScript]
public static function GetHRForLastWin32Error() : int;

戻り値

最終 Win32 エラー コードに対応する HRESULT。

解説

対象の関数には、 setLastError メタデータ フラグが設定されている必要があります。たとえば、 System.Runtime.InteropServices.DllImportAttributeSetLastError フィールドは true にする必要があります。このプロセスは、使用するソース言語によって異なります。C# および C++ の場合は false が既定値ですが、Visual Basic の Declare ステートメントの場合は true です。

メモ   このメソッドは SecurityAction.LinkDemand を使用して、信頼関係のないコードからの呼び出しを防ぎます。 SecurityPermissionAttribute.UnmanagedCode アクセス許可は、直前の呼び出し元にのみ要求されます。信頼性が一部しか確認されていないコードから呼び出すことができるコードの場合、ユーザー入力を検証せずに Marshal クラスに渡すことは避けてください。 LinkDemand メンバの使用に関する重要な制約事項については、「 Demand と LinkDemand 」を参照してください。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

Marshal クラス | Marshal メンバ | System.Runtime.InteropServices 名前空間 | DllImportAttribute