Game Development Reference
In-Depth Information
long result = myComponent->CustomMethod2();
sprintf(output, “Result: %d”, result);
::MessageBox(0, output, “Test CustomMethod2()”, 0);
//Note: System.String is Marshaled into a _bstr_t with COM Interop
_bstr_t inputMessage = _T(“This is a test”);
_bstr_t message = myComponent->CustomMethod3(inputMessage);
sprintf(output, “Message: %s”, (char *)message);
::MessageBox(0, output, “Test CustomMethod3()”, 0);
}
else
{
::MessageBox(0, “Error loading MyComponent COM object!”, “Error”, 0);
}
::CoUninitialize();
}
As you can see, consuming exposed .NET components is easy once they have been
properly configured and registered for COM Interop. The biggest gotcha when
consuming exposed components is finding out what complex types in .NET are
marshaled, as in the type library ( System.String to _bstr_t , for example). This is
easy enough to spot by looking at the generated type library file.
Deployment Considerations
Managed .NET assemblies can be deployed as private or shared. Private deploy-
ment makes an assembly only available to clients that exist in the same directory
as the private assembly, while shared assemblies are installed into the Global
Assembly Cache (GAC), making them available to any local client. Ultimately, the
choice about whether to deploy your .NET assemblies as private or shared is up to
you.
If you choose to use private assemblies, you should also use the /codebase switch
with the regasm.exe utility. You must ensure that you deploy all private assemblies
alongside the client applications that utilize them.
COM exposed assemblies must be strongly named, so you can use the sn.exe tool
to create a strong name key that that you can sign your assembly with. Afterwards,
you can install your shared assembly into the GAC by using the gacutil.exe tool.
Search Nedrilad ::




Custom Search