Game Development Reference
types for each platform. The marshaling of parameters and return values between
managed and unmanaged applications is handled through the Interop Marshaler,
also used by COM Interop.
Platform Invocation Service is covered in much greater detail in Part V, “Techniques
for Legacy Interoperability,” along with sample code on how to reference DLL
exports in C#.
COM and Runtime Callable Wrappers
At some point you may need to interact with a COM object in a .NET application,
and reconciliation between the .NET garbage collection model and the COM ref-
erence counting model is needed to allow both platforms to communicate with
each other. In order for .NET to use a COM object, a Runtime Callable Wrapper
(RCW) must be generated to cater to the differences between the lifetime man-
agement of .NET and COM objects. Runtime Callable Wrappers manage the ref-
erence counted lifetime of COM objects and also handle the marshaling of para-
meters and return types.
Additionally, .NET objects can also be exported to act like a COM object to use
within a legacy application. This functionality is useful for applications that must
remain unmanaged for the time being, but would benefit from the robustness of
the .NET Class Framework.
Runtime Callable Wrappers and COM interoperability are covered in much
greater detail in Part V along with sample code on how to use COM objects in
.NET, and how to use .NET objects like COM objects in legacy applications.
C++/CLI (Managed Extensions for C++)
With such a following of developers using unmanaged C++ for application devel-
opment, especially in the game development industry, there was a need for an
enhancement to the C++ language that would allow programs written in C++ to
use the .NET Class Framework and target the Common Language Runtime. It was
for this reason that Microsoft created C++/CLI (formerly known as Managed
Extensions for C++), an extension of the C++ language that could use the benefits
from the .NET platform without requiring the user to learn a new programming
In other CLR languages like Visual Basic and C#, the only way to invoke Win32
API routines is through explicit use of the P/Invoke mechanism. Developers using