November 24th, 2014

Random API of the day

Today’s random API is CoCreateInstance, the gateway to the world of Microsoft’s COM object technology.

COM, for those of you who haven’t had the pleasure, is a method for objects to publish an interface with a system, and then allow programs to call that object across language, process, or even system boundaries.   Programs that want to use a COM object begin by calling CoCreateInstance() or CoCreateInstanceEx().

Many things in Microsoft land are COM objects.  For instance, I just found out today that the new user-mode driver mechanism in Vista requires that drivers publish COM interfaces for the system to call.  Windows also includes a rich set of COM objects to do all kinds of things, like speech synthesis, start an embedded web browser, do a background download, and so forth.  Some things in Windows, like the speech synthesizer, are only available via their COM interfaces.

CoCreateInstance returns a funny value called a HRESULT, which is different from all the other mutually incompatible return value systems found in Windows.  Because the HRESULT system supports the notion of a conditional success — that is, the function succeeded but something funny happened on the way — it’s wise to use the FAILED() and SUCCEEDED() macros when testing a returned HRESULT for success or failure.

Leave a Response

Imhotep theme designed by Chris Lin. Proudly powered by Wordpress.
XHTML | CSS | RSS | Comments RSS