ExtensibleClassFactory 類別

定義

啟用在建立期間從 Unmanaged 物件延伸的 Managed 物件的自訂。

public ref class ExtensibleClassFactory sealed
public sealed class ExtensibleClassFactory
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ExtensibleClassFactory
type ExtensibleClassFactory = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type ExtensibleClassFactory = class
Public NotInheritable Class ExtensibleClassFactory
繼承
ExtensibleClassFactory
屬性

範例

delegate註冊 ,每當從 Unmanaged 型別擴充的 Managed 型別實例需要配置匯總的 Unmanaged 物件時,就會呼叫 。 這 delegate 預期會配置和匯總 Unmanaged 物件,並呼叫 來取代 CoCreateInstance 。 這個常式必須在進行回呼之類別的 static 初始化運算式內容中呼叫。

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

備註

ExtensibleClassFactory可讓使用者指定 delegate 在建構執行時間可呼叫包裝函式期間呼叫的 , (RCW) 提供基礎 COM 物件的實例。 實際上,回呼會做為 RCW 所包裝之 COM 物件的類別處理站。 如果沒有回呼,Common Language Runtime 會呼叫 CoCreateInstance 來建立基礎 COM 物件。 此回呼提供啟用基礎物件的替代方式,例如 COM Moniker 或提供單一物件。 必須在 RegisterObjectCreationCallback 擴充 RCW 之類別的初始化運算式中 static 呼叫 方法。 每個物件類型只允許一個物件建立回呼。 啟動可延伸 RCW 時,會註冊回呼。 需要建立基礎 COM 物件時,會呼叫回呼以提供物件的參考。 回呼必須傳回 IUnknown 基底物件的介面指標。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
RegisterObjectCreationCallback(ObjectCreationDelegate)

登錄從 Unmanaged 型別延伸的 Managed 型別的執行個體需要配置匯總的 Unmanaged 物件時會呼叫的 delegate

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於