ExtensibleClassFactory Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <ComVisibleAttribute(True)> _ Public NotInheritable Class ExtensibleClassFactory 'Usage Dim instance As ExtensibleClassFactory
/** @attribute ComVisibleAttribute(true) */ public final class ExtensibleClassFactory
ComVisibleAttribute(true) public final class ExtensibleClassFactory
Not applicable.
The ExtensibleClassFactory allows users to specify a delegate that is called during construction of a runtime callable wrapper (RCW) that provides an instance of the underlying COM object. In effect, the callback acts as the class factory for the COM object wrapped by the RCW. Without the callback, the common language runtime creates the underlying COM object by calling CoCreateInstance. This callback provides an alternative way of activating the underlying object, such as with a COM moniker or by providing a singleton object. The RegisterObjectCreationCallback method must be called in the static initializer of the class that is extending the RCW. Only one object creation callback is permitted per object type. When the extensible RCW is activated, the callback is registered. When the underlying COM object needs to be created, the callback is called to provide a reference to the object. The callback must return an IUnknown interface pointer for the base object.
Registers a delegate that will be called whenever an instance of a managed type that extends from an unmanaged type needs to allocate the aggregated unmanaged object. This delegate is expected to allocate and aggregate the unmanaged object and is called in place of a CoCreateInstance. This routine must be called in the context of the static initializer for the class for which the callbacks will be made.
Imports System Imports System.Runtime.InteropServices Public Class CallBack Public Function Activate(Aggregator As IntPtr) As IntPtr Dim oCOM As New ECFSRV32Lib.ObjectActivator() Dim itf As ECFSRV32Lib.IObjectActivator = _ CType(oCOM, ECFSRV32Lib.IObjectActivator) Return New IntPtr(itf.CreateBaseComponent(Aggregator.ToInt32())) End Function End Class ' ' The EcfInner class. First .NET class derived directly from COM class. ' Public Class EcfInner Inherits ECFSRV32Lib.BaseComponent Private Shared callbackInner As CallBack Shared Sub RegisterInner() callbackInner = New CallBack() ExtensibleClassFactory.RegisterObjectCreationCallback( _ New System.Runtime.InteropServices.ObjectCreationDelegate( _ AddressOf callbackInner.Activate)) End Sub 'This is the static initializer. Shared Sub New() RegisterInner() End Sub End Class
package ECFSRV32Lib;
import System.*;
import System.Runtime.InteropServices.*;
public class CallBack
{
public IntPtr Activate(IntPtr Aggregator)
{
ECFSRV32Lib.ObjectActivator oCOM = new ECFSRV32Lib.ObjectActivator();
ECFSRV32Lib.IObjectActivator iTf= (ECFSRV32Lib.IObjectActivator)(oCOM);
return (new IntPtr(iTf.CreateBaseComponent((Aggregator).ToInt32())));
} //Activate
} //CallBack
//
// The EcfInner class. First .NET class derived directly from COM class.
//
public class EcfInner extends ECFSRV32Lib.BaseComponent
{
private static CallBack callbackInner;
static void RegisterInner()
{
callbackInner = new CallBack();
System.Runtime.InteropServices.ExtensibleClassFactory.
RegisterObjectCreationCallback(new System.Runtime.
InteropServices.ObjectCreationDelegate(callbackInner.Activate));
} //RegisterInner
//This is the static initializer.
static
{
RegisterInner();
} //EcfInner
} //EcfInner
Windows 98, Windows Server 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
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.