ComImportAttribute クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(True)> _ <AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface, Inherited:=False)> _ Public NotInheritable Class ComImportAttribute Inherits Attribute
[ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface, Inherited=false)] public sealed class ComImportAttribute : Attribute
[ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface, Inherited=false)] public ref class ComImportAttribute sealed : public Attribute

この属性は、タイプ ライブラリをインポートするときに タイプ ライブラリ インポータ (Tlbimp.exe) が基本的に自動適用しますが、クラスまたはインターフェイスに適用することもできます。
ComImportAttribute は、その型が以前に公開されたタイプ ライブラリで定義されていたことを示す疑似カスタム属性です。共通言語ランタイムは、アクティブ化、エクスポート、強制変換などの実行時に、これらの型を異なる方法で扱います。
![]() |
---|
マネージ オブジェクトによって継承されるすべての基本 COM 型は、フリー スレッド マーシャラ (FTM) を集約する必要があります。FTM が集約されていない COM 型をマネージ オブジェクトが継承することはできません。 |

ComImportAttribute をマネージ インターフェイスの宣言に適用する方法を次の例に示します。この属性を適用するのは、ソース コードで手作業による相互運用機能アセンブリの生成を行い、Tlbimp.exe によって生成されるメタデータをシミュレートする場合だけです。
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)> 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 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; } } }
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(); } };
import System.*; import 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. /** @attribute ComImport() */ /** @attribute Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26") */ public interface IMyStorage { /** @attribute DispId(1) */ Object GetItem( /** @attribute In() @attribute MarshalAs(UnmanagedType.BStr) */String bstrName); /** @attribute DispId(2) */ void GetItems( /** @attribute In() @attribute MarshalAs(UnmanagedType.BStr) */String bstrLocation, /** @attribute Out() @attribute MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT) */Object Items[]); /** @attribute DispId(3) */ void GetItemDescriptions( /** @attribute In() */String bstrLocation, /** @attribute In() @attribute Out() @attribute MarshalAs(UnmanagedType.SafeArray) */Object varDescriptions[]); /** @attribute DispId(4) */ /** @return MarshalAs(UnmanagedType.VariantBool) */ boolean get_IsEmpty(); } //IMyStorage

System.Attribute
System.Runtime.InteropServices.ComImportAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からComImportAttribute クラスを検索する場合は、下記のリンクをクリックしてください。

- ComImportAttribute クラスのページへのリンク