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)


このページでは「.NET Framework クラス ライブラリ リファレンス」からComImportAttribute クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からComImportAttribute クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からComImportAttribute クラス を検索

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

辞書ショートカット

すべての辞書の索引

「ComImportAttribute クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS