ExtensibleClassFactory ExtensibleClassFactory ExtensibleClassFactory ExtensibleClassFactory Class

Definición

Permite personalizar objetos administrados que se extienden a partir de objetos no administrados durante su creación.Enables customization of managed objects that extend from unmanaged objects during creation.

public ref class ExtensibleClassFactory sealed
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ExtensibleClassFactory
type ExtensibleClassFactory = class
Public NotInheritable Class ExtensibleClassFactory
Herencia
ExtensibleClassFactoryExtensibleClassFactoryExtensibleClassFactoryExtensibleClassFactory
Atributos

Ejemplos

Registra un delegate que se llamará cada vez que una instancia de un tipo administrado que se extiende desde un tipo no administrado necesite asignar el objeto no administrado agregado.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. Esto delegate se espera para asignar y agregar el objeto no administrado y se llama en lugar de un CoCreateInstance.This delegate is expected to allocate and aggregate the unmanaged object and is called in place of a CoCreateInstance. Esta rutina debe llamarse en el contexto de la static inicializador de la clase para el que se realizarán las devoluciones de llamada.This routine must be called in the context of the static initializer for the class for which the callbacks will be made.

public ref class CallBack
{
public:
   IntPtr Activate( IntPtr Aggregator )
   {
      ECFSRV32Lib::ObjectActivator^ oCOM = gcnew ECFSRV32Lib::ObjectActivator;
      ECFSRV32Lib::IObjectActivator^ itf = dynamic_cast<ECFSRV32Lib::IObjectActivator^>(oCOM);
      return (IntPtr)itf->CreateBaseComponent( (int)Aggregator );
   }
};

//
// The EcfInner class. First .NET class derived directly from COM class.
//
public ref class EcfInner: public ECFSRV32Lib::BaseComponent
{
private:
   static CallBack^ callbackInner;
   static void RegisterInner()
   {
      callbackInner = gcnew CallBack;
      System::Runtime::InteropServices::ExtensibleClassFactory::RegisterObjectCreationCallback( gcnew System::Runtime::InteropServices::ObjectCreationDelegate( callbackInner, &CallBack::Activate ) );
   }

   //This is the static initializer.    
   static EcfInner()
   {
      RegisterInner();
   }
};
using System;
using System.Runtime.InteropServices;

public class CallBack
{
   public IntPtr Activate(IntPtr Aggregator)
   {
      ECFSRV32Lib.ObjectActivator oCOM = new ECFSRV32Lib.ObjectActivator();
      ECFSRV32Lib.IObjectActivator itf = (ECFSRV32Lib.IObjectActivator)oCOM;
      return (IntPtr) itf.CreateBaseComponent((int)Aggregator);
   }
}

//
// The EcfInner class. First .NET class derived directly from COM class.
//
public class EcfInner : ECFSRV32Lib.BaseComponent
{
   static CallBack callbackInner;

   static void RegisterInner()
   {      
      callbackInner = new CallBack();
      System.Runtime.InteropServices.ExtensibleClassFactory.RegisterObjectCreationCallback(new System.Runtime.InteropServices.ObjectCreationDelegate(callbackInner.Activate));
   }

   //This is the static initializer.    
   static EcfInner()
   {
      RegisterInner();
   }
}
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

Comentarios

El ExtensibleClassFactory permite a los usuarios especificar un delegate que se llama durante la construcción de un contenedor invocable en tiempo de ejecución (RCW) que proporciona una instancia del objeto COM subyacente.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. De hecho, la devolución de llamada actúa como el generador de clases para el objeto COM ajustado por el contenedor RCW.In effect, the callback acts as the class factory for the COM object wrapped by the RCW. Sin la devolución de llamada, common language runtime crea el objeto COM subyacente mediante una llamada a CoCreateInstance.Without the callback, the common language runtime creates the underlying COM object by calling CoCreateInstance. Esta devolución de llamada proporciona una manera alternativa de activar el objeto subyacente, como con un moniker COM o proporcionando un objeto singleton.This callback provides an alternative way of activating the underlying object, such as with a COM moniker or by providing a singleton object. El RegisterObjectCreationCallback método debe llamarse el static inicializador de la clase que extiende el RCW.The RegisterObjectCreationCallback method must be called in the static initializer of the class that is extending the RCW. Se permite la devolución de llamada de creación de un solo objeto por tipo de objeto.Only one object creation callback is permitted per object type. Cuando se activa el RCW extensible, se registra la devolución de llamada.When the extensible RCW is activated, the callback is registered. Cuando el objeto COM subyacente debe crearse, la devolución de llamada se llama para proporcionar una referencia al objeto.When the underlying COM object needs to be created, the callback is called to provide a reference to the object. La devolución de llamada debe devolver un IUnknown puntero de interfaz para el objeto base.The callback must return an IUnknown interface pointer for the base object.

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
RegisterObjectCreationCallback(ObjectCreationDelegate) RegisterObjectCreationCallback(ObjectCreationDelegate) RegisterObjectCreationCallback(ObjectCreationDelegate) RegisterObjectCreationCallback(ObjectCreationDelegate)

Registra un delegate al que se llama cuando una instancia de un tipo administrado que se extienda a partir de un tipo no administrado necesite asignar el objeto no administrado agregado.Registers a delegate that is called when an instance of a managed type, that extends from an unmanaged type, needs to allocate the aggregated unmanaged object.

ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Se aplica a