ComImportAttribute-Klasse
Veröffentlicht: Oktober 2016
Gibt an, dass der attributierte Typ zuvor in COM definiert wurde.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Vererbungshierarchie
System.Object
System.Attribute
System.Runtime.InteropServices.ComImportAttribute
Syntax
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface,
Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class ComImportAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class | AttributeTargets::Interface,
Inherited = false)]
[ComVisibleAttribute(true)]
public ref class ComImportAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface,
Inherited = false)>]
[<ComVisibleAttribute(true)>]
type ComImportAttribute =
class
inherit Attribute
end
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface,
Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class ComImportAttribute
Inherits Attribute
Konstruktoren
Name | Beschreibung | |
---|---|---|
ComImportAttribute() | Initialisiert eine neue Instanz des ComImportAttribute. |
Eigenschaften
Name | Beschreibung | |
---|---|---|
TypeId | Ruft bei Implementierung in einer abgeleiteten Klasse einen eindeutigen Bezeichner für dieses Attribute ab.(Geerbt von „Attribute“.) |
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“.) |
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 classes or interfaces, although the [<topic://cpgrfTypeLibraryImporterTlbimpexe>] typically applies it for you when it imports a type library.
ComImportAttribute is a pseudo-custom attribute that indicates that a type has been defined in a previously published type library. The common language runtime treats these types differently when activating, exporting, coercing, and so on.
Hinweis
All base COM types that are inherited by a managed object must aggregate the Free Threaded Marshaller (FTM). COM types that do not aggregate the FTM can't be inherited by managed objects.
Beispiele
The following example demonstrates how to apply the T:System.Runtime.InteropServices.ComImportAttribute to a managed interface declaration. You apply this attribute only when generating an interop assembly manually in source code, and want to simulate the metadata produced by Tlbimp.exe.
using System;
using System.Runtime.InteropServices;
namespace MyModule
{
// If you do not have a type library for an interface
// you can redeclare it using ComImportAttribute.
// This is how the interface would look in an idl file.
//[
//object,
//uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"),
//dual, helpstring("IMyStorage Interface"),
//pointer_default(unique)
//]
//interface IMyStorage : IDispatch
//{
// [id(1)]
// HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem);
// [id(2)]
// HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems);
// [id(3)]
// HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems);
// [id(4), propget]
// HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty);
//};
// This is the managed declaration.
[ComImport]
[Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")]
public interface IMyStorage
{
[DispId(1)]
[return : MarshalAs( UnmanagedType.Interface )]
Object GetItem( [In, MarshalAs( UnmanagedType.BStr )] String bstrName );
[DispId(2)]
void GetItems( [In, MarshalAs( UnmanagedType.BStr )] String bstrLocation,
[Out, MarshalAs( UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_VARIANT )] out Object[] Items );
[DispId(3)]
void GetItemDescriptions( [In] String bstrLocation,
[In, Out, MarshalAs( UnmanagedType.SafeArray )] ref Object[] varDescriptions );
bool IsEmpty
{
[DispId(4)]
[return : MarshalAs( UnmanagedType.VariantBool )]
get;
}
}
}
Imports System
Imports System.Runtime.InteropServices
Module MyModule
' If you do not have a type library for an interface
' you can redeclare it using ComImportAttribute.
' This is how the interface would look in an idl file.
'[
'object,
'uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"),
'dual, helpstring("IMyStorage Interface"),
'pointer_default(unique)
']
'interface IMyStorage : IDispatch
'{
' [id(1)]
' HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem);
' [id(2)]
' HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems);
' [id(3)]
' HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems);
' [id(4), propget]
' HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty);
'};
' This is the managed declaration.
<ComImport(), Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")> _
Public Interface IMyStorage
<DispId(1)> _
Function GetItem(<InAttribute(), MarshalAs(UnmanagedType.BStr)> ByVal bstrName As String) _
As <MarshalAs(UnmanagedType.Interface)> Object
<DispId(2)> _
Function GetItems(<InAttribute(), MarshalAs(UnmanagedType.BStr)> ByVal bstrLocation As String, _
<OutAttribute(), MarshalAs(UnmanagedType.SafeArray, SafeArraySubType := VarEnum.VT_VARIANT)> _
ByVal Items() As Object)
<DispId(3)> _
Function GetItemDescriptions(<InAttribute()> ByVal bstrLocation As String, _
<InAttribute(), OutAttribute(), _
MarshalAs(UnmanagedType.SafeArray)> ByRef varDescriptions() As Object)
<DispId(4)> _
ReadOnly Property IsEmpty(<MarshalAs(UnmanagedType.VariantBool)> ByVal bEmpty As Boolean)
End Interface
End Module
using namespace System;
using namespace System::Runtime::InteropServices;
// If you do not have a type library for an interface
// you can redeclare it using ComImportAttribute.
// This is how the interface would look in an idl file.
//[
//object,
//uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"),
//dual, helpstring("IMyStorage Interface"),
//pointer_default(unique)
//]
//interface IMyStorage : IDispatch
//{
// [id(1)]
// HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem);
// [id(2)]
// HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems);
// [id(3)]
// HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems);
// [id(4), propget]
// HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty);
//};
// This is the managed declaration.
[ComImport]
[Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")]
interface class IMyStorage
{
[DispId(1)]
Object^ GetItem( [In,MarshalAs(UnmanagedType::BStr)]String^ bstrName );
//[return : MarshalAs(UnmanagedType::Interface)]
[DispId(2)]
void GetItems( [In,MarshalAs(UnmanagedType::BStr)]String^ bstrLocation, [Out,MarshalAs(UnmanagedType::SafeArray,
SafeArraySubType=VarEnum::VT_VARIANT)]array<Object^>^Items );
[DispId(3)]
void GetItemDescriptions( [In]String^ bstrLocation, [In,Out,MarshalAs(UnmanagedType::SafeArray)]array<Object^>^varDescriptions );
property bool IsEmpty
{
[DispId(4)]
[returnvalue:MarshalAs(UnmanagedType::VariantBool)]
bool get();
}
};
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
System.Runtime.InteropServices-Namespace
Tlbimp.exe (Type Library Importer)
Zurück zum Anfang