A Simple COM Tutorial
by Odin Jensen

Download the tutorial program here - (180k)

For a quick test run ComTest\Debug\ComTest.exe (Run Install Components.bat first!)

To Uninstall the components run Uninstall.bat

This simple COM tutorial just creates to fictive "renders" as COM objects and shows how to select a between different components that support the same interface.

Disclaimer: This has nothing to do with a real render. It's only a COM test.

Important: COM interfaces cannot change, or you must create a completely new interface and still retain the old one. (Like DirectX) As long as you don't alter the interface you can change the code to your heart's content without requiring a recompile of the client that uses the component. If two apps use the same component it's only loaded once and unloaded when all are done using it via refcounting.

API hint: If you have different components for each API, don't expose it to the outside world. That way a user of, say, the DirectX8 render will only need the runtime and not the SDK. (+ that's the whole point of one interface and different implementations :)

Common pitfall: Don't forget to include a *.def file or exported functions can't be seen by COM.

If you have questions mail com_me@nukesoftware.com

Have fun and make component based systems :)

Odin Jensen
Lead Programmer
Nuke Software

Discuss this article in the forums


Date this article was posted to GameDev.net: 2/2/2001
(Note that this date does not necessarily correspond to the date the article was written)

See Also:
Sweet Snippets
Windows

© 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!