クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
以前のバージョン
.NET Framework SDK 2.0
System.Runtime.InteropServices
DllImportAttribute クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.NET Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
DllImportAttribute クラス

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

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

Visual Basic (宣言)
<AttributeUsageAttribute(AttributeTargets.Method, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class DllImportAttribute
    Inherits Attribute
Visual Basic (使用法)
Dim instance As DllImportAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Method, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class DllImportAttribute : Attribute
C++
[AttributeUsageAttribute(AttributeTargets::Method, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class DllImportAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DllImportAttribute extends Attribute
JScript
AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) 
ComVisibleAttribute(true) 
public final class DllImportAttribute extends Attribute

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

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

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

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

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

メモメモ

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

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

Visual Basic
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
C#
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) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

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
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker