Export (0) Print
Expand All

ComRegisterFunctionAttribute Class

Specifies the method to call when you register an assembly for use from COM; this allows for the execution of user-written code during the registration process.

For a list of all members of this type, see ComRegisterFunctionAttribute Members.

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

[Visual Basic]
<AttributeUsage(AttributeTargets.Method)>
NotInheritable Public Class ComRegisterFunctionAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Method)]
public sealed class ComRegisterFunctionAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Method)]
public __gc __sealed class ComRegisterFunctionAttribute : public
   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Method)
class ComRegisterFunctionAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

You can apply this attribute to methods.

ComRegisterFunctionAttribute enables you to add abritrary registration code to accommodate the requirements of COM clients. For example, you can update the registry using registration functions from the Microsoft.Win32 namespace. If you provide a registration method, you must also apply System.Runtime.InteropServices.ComUnregisterFunctionAttribute to an unregistration method, which reverses the operations done in the registration method.

The common language runtime calls the method with this attribute when its containing assembly is registered (directly or indirectly) with the Assembly Registration Tool (Regasm.exe) or through the RegistrationServices.RegisterAssembly API method. Methods with this attribute can have any visibility (public, private, and so on), but must be static (Shared in Visual Basic) and must take a single Type parameter for the type to register.

Example

The following example demonstrates how to apply ComRegisterFunctionAttribute and ComUnregisterFunctionAttribute to methods with the appropriate signature.

[Visual Basic] 
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

[C#] 
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.
   }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;

public __gc class MyClassThatNeedsToRegister
{
public:
   [ComRegisterFunctionAttribute]
   static void RegisterFunction(Type* t)
   {
      //Insert code here.
   }
   
public:
   [ComUnregisterFunctionAttribute]
   static void UnregisterFunction(Type* t)
   {
      //Insert code here.
   }
};

[JScript] 
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.
   }
}

Requirements

Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

ComRegisterFunctionAttribute Members | System.Runtime.InteropServices Namespace | ComUnregisterFunctionAttribute | Assembly Registration Tool (Regasm.exe) | RegisterAssembly

Show:
© 2015 Microsoft