Game Development Reference
In-Depth Information
Unmanaged COM Support
As discussed earlier, sometimes it is important to slowly migrate individual com-
ponents in a legacy environment over to the .NET platform. Doing so requires the
ability for .NET and legacy components to communicate with each other. This is
made possible by exposing a COM interface that legacy components can invoke.
We already discussed how to export a COM interface for the specific tool logic, so
now it is time to show the manner in which a legacy component invokes a .NET
When a .NET project is marked with Register for COM Interop , a .tlb file is gener-
ated that contains the exported symbols registered with COM. You can import this
file in an unmanaged application and have all the necessary information to invoke
the COM object.
Here is the code for an unmanaged application invoking the specific tool logic
assembly via COM:
#include <windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <comutil.h>
// Import the IAlertObjectToolLogic interface type library
#import “..\\AlertObjectToolInterface\\bin\\Debug\\AlertObjectToolInterface.tlb”
// Import the AlertObjectToolLogic type library
#import “..\\AlertObjectTool\\bin\\Debug\\AlertObjectTool.tlb” raw_interfaces_only
WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int show)
// Define an interface pointer suitable for the COM class
CComPtr<AlertObjectToolInterface::IAlertObjectToolLogic> toolLogic;
// Determine the Guid of the COM class to instantiate
CLSID alertObjectToolClassID = __uuidof(AlertObjectTool::AlertObjectToolLogic);
// Attempt to instantiate the COM class
if (SUCCEEDED(toolLogic.CoCreateInstance(alertObjectToolClassID,
Search Nedrilad ::

Custom Search