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

설명

일반적으로 형식 라이브러리 가져오기(Tlbimp.exe)가 형식 라이브러리를 가져올 때 자동으로 이 특성을 적용하지만 직접 클래스나 인터페이스에 이 특성을 적용할 수 있습니다.

ComImportAttribute는 이전에 게시된 형식 라이브러리에 형식이 정의되었음을 나타내는 의사(pseudo) 사용자 지정 특성입니다. 공용 언어 런타임에서는 활성화, 내보내기, 변환 등을 수행할 때 이러한 형식을 다르게 처리합니다.

참고

관리되는 개체가 상속하는 모든 기본 COM 형식은 FTM(자유 스레드된 마샬러)을 집계해야 합니다. FTM을 집계하지 않는 COM 형식은 관리되는 개체에서 상속할 수 없습니다.

예제

다음 예제에서는 ComImportAttribute를 관리되는 인터페이스 선언에 적용하는 방법을 보여 줍니다. 소스 코드에서 수동으로 interop 어셈블리를 생성하고 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) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

ComImportAttribute 멤버
System.Runtime.InteropServices 네임스페이스

기타 리소스

형식 라이브러리 가져오기(Tlbimp.exe)