Export (0) Print
Expand All

RealProxy.SetCOMIUnknown Method

Stores an unmanaged proxy of the object represented by the current instance.

[Visual Basic]
Public Overridable Sub SetCOMIUnknown( _
   ByVal i As IntPtr _
)
[C#]
public virtual void SetCOMIUnknown(
 IntPtr i
);
[C++]
public: virtual void SetCOMIUnknown(
 IntPtr i
);
[JScript]
public function SetCOMIUnknown(
   i : IntPtr
);

Parameters

i
A pointer to the IUnknown interface for the object represented by the current proxy instance.

Remarks

When an unmanaged proxy attempts to communicate with the common language runtime through COM, the runtime resolves the remote object represented by the unmanaged proxy. If the remote object is managed and also resides in a common language environment, then instead of communicating with it through distributed COM, the object is sent to the current process.

If the remote object is not derived from MarshalByRefObject, then it is serialized and copied to the current location. If it is derived from MarshalByRefObject, then it returns a transparent proxy, and the remoting infrastructure caches the unmanaged proxy (the IUnknown interface) in the transparent proxy for future use.

Example

[Visual Basic] 
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

[C#] 
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;
}

[C++] 
public:
   IntPtr SupportsInterface(Guid* /*myGuid*/)
   {
      Console::WriteLine(S"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;
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

RealProxy Class | RealProxy Members | System.Runtime.Remoting.Proxies Namespace

Show:
© 2014 Microsoft