ExtensibleClassFactory 類別

定義

啟用在建立期間從 Unmanaged 物件延伸的 Managed 物件的自訂。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
繼承
ExtensibleClassFactory
屬性

範例

delegate註冊, 每當從非受控類型擴充的 managed 類型實例需要配置匯總的非受控物件時, 就會呼叫。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. delegate應該會配置和匯總非受控物件, 並呼叫來取代CoCreateInstanceThis delegate is expected to allocate and aggregate the unmanaged object and is called in place of a CoCreateInstance. 此常式必須在將進行回呼之類別的static初始化運算式內容中呼叫。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.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

備註

可讓使用者delegate指定在執行執行時間可呼叫包裝函式 (RCW) 的過程中呼叫, 以提供基礎 COM 物件的實例。 ExtensibleClassFactoryThe 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. 實際上, 回呼會作為 RCW 所包裝的 COM 物件的 Class Factory。In effect, the callback acts as the class factory for the COM object wrapped by the RCW. 如果沒有回呼, common language runtime 會藉由呼叫CoCreateInstance來建立基礎 COM 物件。Without the callback, the common language runtime creates the underlying COM object by calling CoCreateInstance. 這個回呼會提供啟用基礎物件的替代方式, 例如使用 COM 名字標記或提供單一物件。This callback provides an alternative way of activating the underlying object, such as with a COM moniker or by providing a singleton object. RegisterObjectCreationCallback擴充 RCW 的類別static初始化運算式中, 必須呼叫方法。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. 啟用可延伸的 RCW 時, 會註冊回呼。When the extensible RCW is activated, the callback is registered. 當需要建立基礎 COM 物件時, 會呼叫回呼來提供物件的參考。When the underlying COM object needs to be created, the callback is called to provide a reference to the object. 回呼必須IUnknown傳回基底物件的介面指標。The callback must return an IUnknown interface pointer for the base object.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
RegisterObjectCreationCallback(ObjectCreationDelegate)

登錄從 Unmanaged 型別延伸的 Managed 型別的執行個體需要配置匯總的 Unmanaged 物件時會呼叫的 delegateRegisters 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()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於