Freigeben über


DllImportAttribute-Konstruktor

Initialisiert eine neue Instanz der DllImportAttribute-Klasse mit dem Namen der DLL, die die zu importierende Methode enthält.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Sub New ( _
    dllName As String _
)
'Usage
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
)

Parameter

  • dllName
    Der Name der DLL, die die nicht verwaltete Methode enthält.

Beispiel

Im folgenden Codebeispiel wird die Verwendung des DllImportAttribute-Attributs zum Importieren der Win32-Funktion MessageBox gezeigt. Im Codebeispiel wird dann die importierte Methode aufgerufen.

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);
    }
}

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

DllImportAttribute-Klasse
DllImportAttribute-Member
System.Runtime.InteropServices-Namespace