DllImportAttribute-Klasse
Veröffentlicht: Oktober 2016
Gibt an, dass die attributierte Methode durch eine nicht verwaltete Dynamic Link Library (DLL) als statischer Einstiegspunkt verfügbar gemacht wird.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Vererbungshierarchie
System.Object
System.Attribute
System.Runtime.InteropServices.DllImportAttribute
Syntax
[AttributeUsageAttribute(AttributeTargets.Method, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class DllImportAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class DllImportAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Method, Inherited = false)>]
[<ComVisibleAttribute(true)>]
type DllImportAttribute =
class
inherit Attribute
end
<AttributeUsageAttribute(AttributeTargets.Method, Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class DllImportAttribute
Inherits Attribute
Konstruktoren
Name | Beschreibung | |
---|---|---|
DllImportAttribute(String) | Initialisiert eine neue Instanz der DllImportAttribute -Klasse mit dem Namen der DLL mit der Methode zu importieren. |
Eigenschaften
Name | Beschreibung | |
---|---|---|
TypeId | Ruft bei Implementierung in einer abgeleiteten Klasse einen eindeutigen Bezeichner für dieses Attribute ab.(Geerbt von „Attribute“.) |
|
Value | Ruft den Namen der DLL-Datei, die den Einstiegspunkt enthält. |
Methoden
Name | Beschreibung | |
---|---|---|
Equals(Object) | Diese API unterstützt die Produkt Infrastruktur und sollte nicht direkt aus dem Code verwendet werden. Gibt einen Wert zurück, der angibt, ob diese Instanz gleich einem angegebenen Objekt ist.(Geerbt von „Attribute“.) |
|
GetHashCode() | Gibt den Hashcode für diese Instanz zurück.(Geerbt von „Attribute“.) |
|
GetType() | Ruft den Type der aktuellen Instanz ab.(Geerbt von „Object“.) |
|
IsDefaultAttribute() | Gibt beim Überschreiben in einer abgeleiteten Klasse an, ob der Wert der Instanz der Standardwert für die abgeleitete Klasse ist.(Geerbt von „Attribute“.) |
|
Match(Object) | Ruft beim Überschreiben in einer abgeleiteten Klasse gibt einen Wert, der angibt, ob diese Instanz gleich ein angegebenen Objekt ist.(Geerbt von „Attribute“.) |
|
ToString() | Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.(Geerbt von „Object“.) |
Felder
Name | Beschreibung | |
---|---|---|
BestFitMapping | Aktiviert oder deaktiviert die Zuordnung mit ähnlichen Verhalten bei der Konvertierung von Unicode-Zeichen in ANSI-Zeichen. |
|
CallingConvention | Gibt die Aufrufkonvention eines Einstiegspunktes an. |
|
CharSet | Gibt an, wie Parameter der Methode und die namenszerlegung für Steuerelemente zu marshallen. |
|
EntryPoint | Gibt den Namen oder die Ordnungszahl der DLL-Einstiegspunkt aufgerufen werden. |
|
ExactSpelling | Steuerelemente, ob die DllImportAttribute.CharSet Feld bewirkt, dass die common Language Runtime eine nicht verwaltete DLL-Einstiegspunkt andere als die angegebene Namen gesucht. |
|
PreserveSig | Gibt an, ob nicht verwaltete Methoden, die haben HRESULT oder retval zurückgeben, Werte direkt übersetzt oder ob HRESULT oder retval zurückgeben, Werte automatisch in Ausnahmen konvertiert werden. |
|
SetLastError | Gibt an, ob die aufgerufene Methode ruft die SetLastError Win32-API-Funktion vor der Rückgabe aus die attributierte Methode. |
|
ThrowOnUnmappableChar | Aktiviert bzw. deaktiviert das Auslösen einer Ausnahme bei einer nicht zuzuordnenden Unicode-Zeichen, die in ein ANSI konvertiert wird "?" Zeichen. |
Explizite Schnittstellenimplementierungen
Name | Beschreibung | |
---|---|---|
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | Ordnet eine Reihe von Namen einer entsprechenden Reihe von Dispatchbezeichnern zu.(Geerbt von „Attribute“.) |
|
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | Ruft die Typinformationen für ein Objekt ab, mit deren Hilfe die Typinformationen für eine Schnittstelle abgerufen werden können.(Geerbt von „Attribute“.) |
|
_Attribute.GetTypeInfoCount(UInt32) | Ruft die Anzahl der Schnittstellen mit Typinformationen ab, die von einem Objekt bereitgestellt werden (0 oder 1).(Geerbt von „Attribute“.) |
|
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | Stellt den Zugriff auf von einem Objekt verfügbar gemachte Eigenschaften und Methoden bereit.(Geerbt von „Attribute“.) |
Hinweise
You can apply this attribute to methods.
The T:System.Runtime.InteropServices.DllImportAttribute attribute provides the information needed to call a function exported from an unmanaged DLL. As a minimum requirement, you must supply the name of the DLL containing the entry point.
You apply this attribute directly to C# and C++ method definitions; however, the Visual Basic compiler emits this attribute when you use the Declare statement. For complex method definitions that include F:System.Runtime.InteropServices.DllImportAttribute.BestFitMapping, F:System.Runtime.InteropServices.DllImportAttribute.CallingConvention, F:System.Runtime.InteropServices.DllImportAttribute.ExactSpelling, F:System.Runtime.InteropServices.DllImportAttribute.PreserveSig, F:System.Runtime.InteropServices.DllImportAttribute.SetLastError, or F:System.Runtime.InteropServices.DllImportAttribute.ThrowOnUnmappableChar fields, you apply this attribute directly to Visual Basic method definitions.
Note JScript does not support this attribute. You can use C# or Visual Basic wrapper classes to access unmanaged API methods from JScript programs.
For additional information about using the platform invoke service to access functions in unmanaged DLLs, see [<topic://cpconconsumingunmanageddllfunctions>].
Hinweis
The T:System.Runtime.InteropServices.DllImportAttribute does not support marshaling of generic types.
Beispiele
The following code example shows how to use the T:System.Runtime.InteropServices.DllImportAttribute attribute to import the Win32 MessageBox function. The code example then calls the imported method.
using System;
using System.Runtime.InteropServices;
class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
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);
}
}
Imports System
Imports System.Runtime.InteropServices
Module Example
' Use DllImport to import the Win32 MessageBox function.
<DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
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
Versionsinformationen
Universelle Windows-Plattform
Verfügbar seit 8
.NET Framework
Verfügbar seit 1.1
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Windows Phone
Verfügbar seit 8.1
Threadsicherheit
Alle öffentlichen statischen Member ( Shared in Visual Basic) dieses Typs sind threadsicher. Die Threadsicherheit für Instanzmember ist nicht garantiert.
Siehe auch
SetLastError
ExactSpelling
PreserveSig
CallingConvention
System.Runtime.InteropServices-Namespace
Zurück zum Anfang