ComRegisterFunctionAttribute 类

指定当注册用于 COM 的程序集时调用的方法;这可以用于注册过程中用户编写代码的执行。

**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Method, Inherited:=False)> _
Public NotInheritable Class ComRegisterFunctionAttribute
    Inherits Attribute
用法
Dim instance As ComRegisterFunctionAttribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Method, Inherited=false)] 
public sealed class ComRegisterFunctionAttribute : Attribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Method, Inherited=false)] 
public ref class ComRegisterFunctionAttribute sealed : public Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) */ 
public final class ComRegisterFunctionAttribute extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) 
public final class ComRegisterFunctionAttribute extends Attribute

备注

可将该属性应用于方法。

ComRegisterFunctionAttribute 使您可以添加任意的注册码,以满足 COM 客户端的要求。例如,可以从 Microsoft.Win32 命名空间使用注册函数更新注册表。如果提供了注册方法,还必须将 System.Runtime.InteropServices.ComUnregisterFunctionAttribute 应用于注销方法,以撤销在注册方法中所进行的操作。

当使用 程序集注册工具 (Regasm.exe) 或通过 RegistrationServices.RegisterAssembly API 方法(直接或间接)注册公共语言运行库的包含程序集时,运行库将使用此属性调用该注销方法。具有此属性的方法可以具有任何可见性(公共、私有等),但必须是 static,并且必须为要注册的类型采用一个 Type 参数。

示例

下面的示例演示了如何将 ComRegisterFunctionAttributeComUnregisterFunctionAttribute 应用于方法,并在应用的同时加以适当的签名。

Imports System
Imports System.Runtime.InteropServices

Public Class MyClassThatNeedsToRegister
    
    <ComRegisterFunctionAttribute()> Public Shared Sub _
      RegisterFunction(t As Type)
        'Insert code here.
    End Sub
    
    <ComUnregisterFunctionAttribute()> Public Shared Sub _
      UnregisterFunction(t As Type)
        'Insert code here.
    End Sub
End Class
using System;
using System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
{
   [ComRegisterFunctionAttribute]
   public static void RegisterFunction(Type t)
   {
      //Insert code here.
   }
   
   [ComUnregisterFunctionAttribute]
   public static void UnregisterFunction(Type t)
   {
      //Insert code here.
   }
}
using namespace System;
using namespace System::Runtime::InteropServices;
public ref class MyClassThatNeedsToRegister
{
public:

   [ComRegisterFunctionAttribute]
   static void RegisterFunction( Type^ t )
   {
      
      //Insert code here.
   }


   [ComUnregisterFunctionAttribute]
   static void UnregisterFunction( Type^ t )
   {
      
      //Insert code here.
   }

};
import System.*;
import System.Runtime.InteropServices.*;

public class MyClassThatNeedsToRegister
{
    /** @attribute ComRegisterFunctionAttribute()
     */
    public static void RegisterFunction(Type t)
    {
        //Insert code here.
    } //RegisterFunction

    /** @attribute ComUnregisterFunctionAttribute()
     */
    public static void UnregisterFunction(Type t)
    {
        //Insert code here.
    } //UnregisterFunction
} //MyClassThatNeedsToRegister
import System;
import System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
{
   ComRegisterFunctionAttribute public static function RegisterFunction(t : Type) : void 
   {
      //Insert code here.
   }
   
   ComUnregisterFunctionAttribute public static function UnregisterFunction(t : Type) : void
   {
      //Insert code here.
   }
}

继承层次结构

System.Object
   System.Attribute
    System.Runtime.InteropServices.ComRegisterFunctionAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、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

请参见

参考

ComRegisterFunctionAttribute 成员
System.Runtime.InteropServices 命名空间
ComUnregisterFunctionAttribute
RegisterAssembly

其他资源

程序集注册工具 (Regasm.exe)