共用方式為


RealProxy.SetCOMIUnknown(IntPtr) 方法

定義

存放目前執行個體所代表物件的 Unmanaged Proxy。

public:
 virtual void SetCOMIUnknown(IntPtr i);
public virtual void SetCOMIUnknown (IntPtr i);
abstract member SetCOMIUnknown : nativeint -> unit
override this.SetCOMIUnknown : nativeint -> unit
Public Overridable Sub SetCOMIUnknown (i As IntPtr)

參數

i
IntPtr

nativeint

指標,指向目前 Proxy 執行個體所代表物件的 IUnknown 介面。

範例

[SecurityPermission(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::Infrastructure)]
IntPtr SupportsInterface( Guid * /*myGuid*/ )
{
   Console::WriteLine( "SupportsInterface method called" );
   
   // Object reference is requested for communication with unmanaged objects
   // in the current process through COM.
   IntPtr myIntPtr = this->GetCOMIUnknown( false );
   
   // Stores an unmanaged proxy of the object.
   this->SetCOMIUnknown( myIntPtr );
   
   // return COM Runtime Wrapper pointer.
   return myIntPtr;
}
public override IntPtr SupportsInterface(ref Guid myGuid)
{
    Console.WriteLine("SupportsInterface method called");
    // Object reference is requested for communication with unmanaged objects
    // in the current process through COM.
    IntPtr myIntPtr = this.GetCOMIUnknown(false);
    // Stores an unmanaged proxy of the object.
    this.SetCOMIUnknown(myIntPtr);
    // return COM Runtime Wrapper pointer.
    return myIntPtr;
}
<SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
Public Overrides Function SupportsInterface(ByRef myGuid As Guid) As IntPtr
   Console.WriteLine("SupportsInterface method called")
   ' Object reference is requested for communication with unmanaged objects
   ' in the current process through COM.
   Dim myIntPtr As IntPtr = Me.GetCOMIUnknown(False)
   ' Stores an unmanaged proxy of the object.
   Me.SetCOMIUnknown(myIntPtr)
   ' return COM Runtime Wrapper pointer.
   Return myIntPtr
End Function 'SupportsInterface

備註

當 Unmanaged Proxy 嘗試透過 COM 與 Common Language Runtime 通訊時,運行時間會解析 Unmanaged Proxy 所代表的遠端物件。 如果遠端物件是受管理,也位於通用語言環境中,則不會透過分散式 COM 與它通訊,而是將對象傳送至目前的進程。

如果遠端物件不是衍生自 MarshalByRefObject,則會串行化並複製到目前的位置。 如果衍生自 MarshalByRefObject,則會傳回透明 Proxy,而遠端基礎結構會快取非受控 Proxy, (IUnknown 透明 Proxy 中的介面) 以供日後使用。

適用於