Marshal.CreateWrapperOfType Method (Object, Type)
Note: This API is now obsolete.
Wraps the specified COM object in an object of the specified type.
Assemblies: System.Runtime.InteropServices (in System.Runtime.InteropServices.dll)
mscorlib (in mscorlib.dll)
[ObsoleteAttribute("CreateWrapperOfType(Object, Type) may be unavailable in future releases. Instead, use CreateWrapperOfType<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296519")] public static Object CreateWrapperOfType( Object o, Type t )
- Type: System.Object
The object to be wrapped.
- Type: System.Type
The type of wrapper to create.
Return ValueType: System.Object
The newly wrapped object that is an instance of the desired type.
CreateWrapperOfType converts one COM class type, typically the generic __ComObject type, to another COM class type. The input COM object, represented by parameter o, is a Runtime Callable Wrapper (RCW).
Both the t and o parameters must be classes whose signatures are attributed with System.Runtime.InteropServices.ComImportAttribute. The Tlbimp.exe (Type Library Importer) tool applies this attribute for you when it imports a type library. If you create the RCW manually in source code, you should apply this attribute to the managed signature that represents the original coclass to signify its COM origins.
Tlbimp.exe imports a COM coclass as a managed class and an interface. The coclass interface has the same name as the original coclass, and the managed class has the original coclass name appended with "Class". For example, a coclass called MyCoclass becomes a coclass interface called MyCoclass and a managed class called MyCoclassClass. Since t must be a class, not an interface, be sure to specify the managed class (MyCoclassClass) and not the coclass interface.
You lose the identity of the input COM object because a new RCW instance wraps the IUnknown pointer exposed by the original RCW.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.