RealProxy.SetCOMIUnknown(IntPtr) 方法

定义

存储当前实例所表示的对象的非托管代理。

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

一个指针,指向当前代理实例所表示的对象的 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

注解

当非托管代理尝试通过 COM 与公共语言运行时通信时,运行时将解析由非托管代理表示的远程对象。 如果远程对象是托管的,并且也驻留在公共语言环境中,则对象将发送到当前进程,而不是通过分布式 COM 与其通信。

如果远程对象不是派生自 MarshalByRefObject,则会对其进行序列化并复制到当前位置。 如果它派生自 MarshalByRefObject,则返回透明代理,远程处理基础结构将缓存非托管代理 (IUnknown 透明代理中的接口) 供将来使用。

适用于