DllImportAttributeとは? わかりやすく解説

DllImportAttribute クラス

属性付きメソッドがアンマネージ DLL (Dynamic-Link Library) によって静的エントリ ポイントとして公開されることを示します

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Method, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 DllImportAttribute
    Inherits Attribute
Dim instance As DllImportAttribute
[AttributeUsageAttribute(AttributeTargets.Method, Inherited=false)]
 
[ComVisibleAttribute(true)] 
public sealed class DllImportAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, Inherited=false)]
 
[ComVisibleAttribute(true)] 
public ref class DllImportAttribute sealed
 : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, Inherited=false)
 */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DllImportAttribute extends
 Attribute
AttributeUsageAttribute(AttributeTargets.Method, Inherited=false)
 
ComVisibleAttribute(true) 
public final class DllImportAttribute extends
 Attribute
解説解説

この属性は、メソッド適用できます

DllImportAttribute 属性は、アンマネージ DLL からエクスポートされた関数呼び出すために必要な情報提供します最低限要件として、エントリ ポイントを含む DLL の名前を指定する必要があります

この属性C# および C++メソッド定義に対して直接適用ます。Visual Basic では、Declare ステートメント使用され場合コンパイラによってこの属性出力されます。BestFitMapping、CallingConvention、ExactSpelling、PreserveSig、SetLastError、ThrowOnUnmappableChar のいずれかフィールドを含む複雑なメソッド定義の場合は、この属性Visual Basicメソッド定義に直接適用ます。

メモ :    JScript はこの属性サポートしていません。JScript プログラムからアンマネージ APIメソッドアクセスするには、C# または Visual Basicラッパー クラス使用します

プラットフォーム呼び出しサービス使用してアンマネージ DLL関数アクセスする方法詳細については、「アンマネージ DLL 関数の処理」を参照してください

メモメモ

DllImportAttribute では、ジェネリック型マーシャリングサポートしていません。

使用例使用例

DllImportAttribute 属性使用して Win32 MessageBox 関数インポートする方法次のコード例示します。このコード例では、インポートしたメソッド呼び出してます。

Imports System
Imports System.Runtime.InteropServices

Module Example

    ' Use DllImport to import the Win32 MessageBox function.
    <DllImport("user32.dll", CharSet:=CharSet.Auto)>
 _
    Function MessageBox(ByVal hwnd As
 IntPtr, ByVal t As String,
 ByVal caption As String, ByVal t2 As UInt32) As Integer
    End Function


    Sub Main()
        ' Call the MessageBox function using platform invoke.
        MessageBox(New IntPtr(0), "Hello World!",
 "Hello Dialog", 0)
    End Sub

End Module
using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int
 MessageBox(IntPtr hWnd, String text, String caption, uint type);
    
    static void Main()
    {
        // Call the MessageBox function using platform invoke.
        MessageBox(new IntPtr(0), "Hello World!", "Hello
 Dialog", 0);
    }
}
継承階層継承階層
System.Object
   System.Attribute
    System.Runtime.InteropServices.DllImportAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DllImportAttribute メンバ
System.Runtime.InteropServices 名前空間
SetLastError
ExactSpelling
PreserveSig
CallingConvention

DllImportAttribute コンストラクタ

DllImportAttribute クラス新しインスタンスを、インポートするメソッド格納した DLL の名前を使用して初期化します。

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    dllName As String _
)
Dim dllName As String

Dim instance As New DllImportAttribute(dllName)
public DllImportAttribute (
    string dllName
)
public:
DllImportAttribute (
    String^ dllName
)
public DllImportAttribute (
    String dllName
)
public function DllImportAttribute (
    dllName : String
)

パラメータ

dllName

アンマネージ メソッド格納する DLL の名前。

使用例使用例

DllImportAttribute 属性使用して Win32 MessageBox 関数インポートする方法次のコード例示します。このコード例では、インポートしたメソッド呼び出してます。

Imports System
Imports System.Runtime.InteropServices

Module Example

    ' Use DllImport to import the Win32 MessageBox function.
    <DllImport("user32.dll", CharSet:=CharSet.Auto)>
 _
    Function MessageBox(ByVal hwnd As
 IntPtr, ByVal t As String,
 ByVal caption As String, ByVal t2 As UInt32) As Integer
    End Function


    Sub Main()
        ' Call the MessageBox function using platform invoke.
        MessageBox(New IntPtr(0), "Hello World!",
 "Hello Dialog", 0)
    End Sub

End Module
using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int
 MessageBox(IntPtr hWnd, String text, String caption, uint type);
    
    static void Main()
    {
        // Call the MessageBox function using platform invoke.
        MessageBox(new IntPtr(0), "Hello World!", "Hello
 Dialog", 0);
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DllImportAttribute クラス
DllImportAttribute メンバ
System.Runtime.InteropServices 名前空間

DllImportAttribute フィールド


パブリック フィールドパブリック フィールド

  名前 説明
パブリック フィールド BestFitMapping Unicode 文字ANSI 文字変換するときの、最適マッピング動作オン/オフ切り替えます
パブリック フィールド .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート ExactSpelling DllImportAttribute.CharSet フィールドで、指定された名前以外のエントリ ポイント名をアンマネージ DLL から共通言語ランタイム検索させるかどうか制御します
パブリック フィールド .NET Compact Framework によるサポート .NET Compact Framework によるサポート ThrowOnUnmappableChar マップできない Unicode 文字 (ANSI の "?" に変換される文字) が見つかったときに、例外スローするかどうか指定します
参照参照

関連項目

DllImportAttribute クラス
System.Runtime.InteropServices 名前空間
SetLastError
ExactSpelling
PreserveSig
CallingConvention

DllImportAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
パブリック プロパティ Value エントリ ポイントを含む DLL ファイルの名前を取得します
参照参照

関連項目

DllImportAttribute クラス
System.Runtime.InteropServices 名前空間
SetLastError
ExactSpelling
PreserveSig
CallingConvention

DllImportAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
参照参照

関連項目

DllImportAttribute クラス
System.Runtime.InteropServices 名前空間
SetLastError
ExactSpelling
PreserveSig
CallingConvention

DllImportAttribute メンバ

属性付きメソッドがアンマネージ DLL (Dynamic-Link Library) によって静的エントリ ポイントとして公開されることを示します

DllImportAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DllImportAttribute DllImportAttribute クラス新しインスタンスを、インポートするメソッド格納した DLL の名前を使用して初期化します。
パブリック フィールドパブリック フィールド
  名前 説明
パブリック フィールド BestFitMapping Unicode 文字ANSI 文字変換するときの、最適マッピング動作オン/オフ切り替えます
パブリック フィールド .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート ExactSpelling DllImportAttribute.CharSet フィールドで、指定された名前以外のエントリ ポイント名をアンマネージ DLL から共通言語ランタイム検索させるかどうか制御します
パブリック フィールド .NET Compact Framework によるサポート .NET Compact Framework によるサポート ThrowOnUnmappableChar マップできない Unicode 文字 (ANSI の "?" に変換される文字) が見つかったときに、例外スローするかどうか指定します
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。(Attribute から継承されます。)
パブリック プロパティ Value エントリ ポイントを含む DLL ファイルの名前を取得します
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
参照参照

関連項目

DllImportAttribute クラス
System.Runtime.InteropServices 名前空間
SetLastError
ExactSpelling
PreserveSig
CallingConvention



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DllImportAttribute」の関連用語

DllImportAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DllImportAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS