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!

Custom Runtime Callable Wrappers (CRCWs)

This section describes customized runtime callable wrappers (CRCWs), which handle calls made from managed to unmanaged code.

A CRCW class is typically used to proxy calls made from managed to unmanaged code. The wrapper class is a garbage-collected class that implements a managed interface and caches a reference to the unmanaged interface. As calls are made on the methods of the managed interface, the wrapper handles the call by delegating the call to the cached, unmanaged interface.

In this example, the CRCW class called NewToOldWrapper implements the managed interface INew and delegates the calls to the unmanaged interface IOld.

In Wrappers.h
__gc class NewToOldWrapper : public INew  {
public:
   NewToOldWrapper (int pIOld);
   void NewMethod(void);

private:
   IOld *m_pIOld;
};

In Wrappers.cpp
#using <mscorlib.dll>
#include <New.h>  
#include <Old.h>  
#include “Wrappers.h” 

NewToOldWrapper::NewToOldWrapper (int pIOld) {
   m_pIOld = (IOld *) pIOld;
};

void NewToOldWrapper::NewMethod() {
   HRESULT hr = m_pIRawOld->OldMethod();
   if FAILED(hr)
      ; // throw exception   
   return; 
};

In the code shown here, the wrapper’s implementation of NewMethod directly calls OldMethod on the IOld interface that the wrapper is referencing. The wrapper could provide an alternative implementation of the NewMethod.