CoClassAttribute クラス
タイプ ライブラリからインポートされるコクラスのクラス ID を指定します。
この型のすべてのメンバの一覧については、CoClassAttribute メンバ を参照してください。
System.Object
System.Attribute
System.Runtime.InteropServices.CoClassAttribute
<AttributeUsage(AttributeTargets.Interface)>
NotInheritable Public Class CoClassAttribute Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Interface)]
public sealed class CoClassAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Interface)]
public __gc __sealed class CoClassAttribute : public Attribute
[JScript]
public
AttributeUsage(AttributeTargets.Interface)
class CoClassAttribute extends Attribute
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
この属性は、タイプ ライブラリをインポートするときに タイプ ライブラリ インポータ (Tlbimp.exe) が基本的に自動適用しますが、コクラスのインターフェイスに明示的に適用することもできます。
Tlbimp.exe を使用してコクラスをインポートすると、そのコクラスを表すマネージ クラスとインターフェイスが作成されます。コクラスのインターフェイスは、元のコクラスの既定のインターフェイスと同じインターフェイス ID (IID) を持ちます。インポートされたコクラスのインターフェイスは、コクラスの名前も保持します。インポートされたクラスを識別できるように、元のコクラスの名前の末尾には Tlbimp.exe によって "class" が自動的に付加されます。
この属性を使用することはほとんどありません。ただし、Tlbimp.exe が生成するメタデータを詳しく再現するソース コードを作成する場合は、各コクラスについてコクラスのインターフェイスを作成しておく必要があります。コクラスのインターフェイスの名前には元のコクラスの名前を使用し、既定のインターフェイスから派生して作成します。また、コクラスのインターフェイスには、 CoClassAttribute に加えて、 System.Runtime.InteropServices.ComImportAttribute と System.Runtime.InteropServices.GuidAttribute も適用する必要があります。Tlbimp.exe がタイプ ライブラリからインターフェイスとコクラスをインポートする方法の詳細については、「 インポート時の型の変換 」を参照してください。
必要条件
名前空間: System.Runtime.InteropServices
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: Mscorlib (Mscorlib.dll 内)
参照
CoClassAttribute メンバ | System.Runtime.InteropServices 名前空間 | ComImportAttribute | GuidAttribute | タイプ ライブラリ インポータ (Tlbimp.exe)