Random API of the day
Jason posted in Uncategorized on May 26th, 2006
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.