ComImportAttributeとは? わかりやすく解説

ComImportAttribute クラス

属性の型が以前COM定義されたことを示します

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

<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface,
 Inherited:=False)> _
Public NotInheritable Class
 ComImportAttribute
    Inherits Attribute
Dim instance As ComImportAttribute
[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
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface,
 Inherited=false) */ 
public final class ComImportAttribute extends
 Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface, Inherited=false)
 
public final class ComImportAttribute extends
 Attribute
解説解説
使用例使用例

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.Object
   System.Attribute
    System.Runtime.InteropServices.ComImportAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ComImportAttribute メンバ
System.Runtime.InteropServices 名前空間
その他の技術情報
タイプ ライブラリ インポータ (Tlbimp.exe)

ComImportAttribute コンストラクタ


ComImportAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
参照参照

関連項目

ComImportAttribute クラス
System.Runtime.InteropServices 名前空間

その他の技術情報

タイプ ライブラリ インポータ (Tlbimp.exe)

ComImportAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
参照参照

関連項目

ComImportAttribute クラス
System.Runtime.InteropServices 名前空間

その他の技術情報

タイプ ライブラリ インポータ (Tlbimp.exe)

ComImportAttribute メンバ

属性の型が以前COM定義されたことを示します

ComImportAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ComImportAttribute ComImportAttribute の新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
参照参照

関連項目

ComImportAttribute クラス
System.Runtime.InteropServices 名前空間

その他の技術情報

タイプ ライブラリ インポータ (Tlbimp.exe)



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ComImportAttribute」の関連用語

ComImportAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ComImportAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS