Returns a managed object of a specified type that represents a COM object.
Assembly: mscorlib (in mscorlib.dll)
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] public static Object GetTypedObjectForIUnknown( IntPtr pUnk, Type t )
- Type: System.IntPtr
A pointer to the IUnknown interface of the unmanaged object.
The t parameter must be either a COM-imported type or a subtype of a COM-imported type. In addition, t must be a type whose metadata was imported by the Type Library Importer (Tlbimp.exe). This type must be a class and not an associated coclass interface, which carries the name of the COM class. For example, suppose Tlbimp.exe imports Myclass as a class called MyclassClass and a coclass interface called Myclass. Be sure to use MyclassClass, not Myclass with this method. For additional information about imported classes and coclass interfaces, see Imported Type Conversion.
If an object has already been obtained for the pUnk parameter, then t is ignored and the existing object is returned. pUnk represents an IUnknown interface pointer; however, because all COM interfaces derive directly or indirectly from IUnknown, you can pass any COM interface to this method. The object returned by is a runtime callable wrapper, which the common language runtime manages as it does any other managed object. For additional information, see Runtime Callable Wrapper.
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.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.