NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Exposing Classic COM objects to the NGWS Runtime

This section describes the mechanism that makes it possible to use COM objects from managed code. This is the mechanism that Runtime clients use to access the services provided by COM objects. When a NGWS runtime client creates an instance of a NGWS object, the object is exposed through a Runtime Callable Wrapper (RCW) that acts as a proxy for the real unmanaged object. These wrappers appear to be just like any other managed class to the NGWS runtime client but they really just marshal calls between managed (NGWS runtime) and unmanaged (classic COM) code. Each COM object being referenced outside the runtime will have a single RCW regardless of the number of references that exist on that object. This ensures that a single object identity is shared between the RCW and the COM object.

Another more advanced techniques for accessing COM object is described in the COM Interop Custom Marshaling specification.

When a NGWS runtime client loads a classic COM object, a Runtime Callable Wrapper (RCW) is created, which looks like a NGWS object to that client. This RCW takes on one of two forms based on how the object was created.

When created as an early bound object, the RCW will be of a specific type and will implement the interfaces the classic COM object implements, and expose as fields any properties available from the coclasses default IDispatch interface. This new NGWS runtime object can be used just like any other managed type. You can cast the object to any of the interface that the object implements and call methods on those interface directly. You can even reflect on the class using the Reflection APIs

Some interfaces on the classic COM object will not be exposed on the NGWS runtime class. These include IUnknown, IDispatch, and IDispatchEx (more to follow). These interfaces are automatically consumed by the RCW and are factored into a different form. For details on how the RCW uses these interfaces see section 5.3 below.

If the object is created in a late bound manner, the RCW will of type System.Object. Users will still be able to reflect on the type and dynamically invoke its members but will only be able to do so through reflection.