Game Development Reference
Accessing from Unmanaged Code
The hardest part is over; you can now work with your exposed component and
start invoking its methods. As covered in the last section, you are now left with a
type library file (.tlb) that you can import into a C++ application (or any other
platform or language supporting COM) to recognize your exposed component.
The unmanaged ClientTest example located on the Companion Web site shows
how to consume the exposed component. The following code describes the source
code to the ClientTest executable (standard Win32 project, unmanaged C++).
Notice how the type library file ( .tlb ) is referenced with the import directive. The
linker will actually generate a second file from this one called a type library header,
which contains some specific C++ wrapper functionality. Both files can be used to
get a better understanding of what is going on behind the scenes of COM Interop.
#import “MyComponent.tlb” no_namespace
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
// Acquire the unique identifier of the COM server (.NET Component)
CLSID myComponentClassID = __uuidof(MyComponent);
// Acquired a reference to the COM server (.NET Component)
“Successfully invoked CustomMethod1()!”,