Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Marshal.GetIUnknownForObject Method

Returns an IUnknown interface from a managed object.

[Visual Basic]
Public Shared Function GetIUnknownForObject( _
   ByVal o As Object _
) As IntPtr
[C#]
public static IntPtr GetIUnknownForObject(
 object o
);
[C++]
public: static IntPtr GetIUnknownForObject(
 Object* o
);
[JScript]
public static function GetIUnknownForObject(
   o : Object
) : IntPtr;

Parameters

o
The object whose IUnknown interface is requested.

Return Value

The IUnknown pointer for the o parameter.

Remarks

In managed code, you seldom work directly with the IUnknown interface. However, GetIUnknownForObject is useful when calling a method that exposes a COM object parameter as an IntPtr type, or with custom marshaling. Calling an object with this method causes the reference count to increment on the interface pointer before the pointer is returned. Always use Marshal.Release to decrement the reference count once you have finished with the pointer. This method provides the opposite functionality of the Marshal.GetObjectForIUnknown method.

You can also use this method on a managed object to obtain an interface pointer to the COM callable wrapper for the object. For additional information, see COM Callable Wrapper.

Note   This method uses SecurityAction.LinkDemand to prevent it from being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass user input to Marshal class methods without validation. For important limitations on using the LinkDemand member, see Demand vs. LinkDemand.

Requirements

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

.NET Framework Security: 

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace | Release | GetObjectForIUnknown

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft