COM Interview questions
Compiled by
RajeshKumar Sitaraman
What is IUnknown? What methods are provided by
IUnknown?
It is a generally good idea to have an answer for this question if you claim you
know COM in your resume. Otherwise, you may consider your interview failed
at this point. IUnknown is the base interface of COM. All other interfaces must
derive directly or indirectly from IUnknown. There are three methods in that
interface: AddRef, Release and QueryInterface.
What are the purposes of AddRef, Release and
QueryInterface functions?
AddRef increments reference count of the object, Release decrements
reference counter of the object and QueryInterface obtains a pointer to the
requested interface.
What should QueryInterface functions do if
requested object was not found?
Return E_NOINTERFACE and nullify its out parameter.
How can would you create an instance of the
object in COM?
Well, it all depends on your project. Start your answer from CoCreateInstance
or CoCreateInstanceEx, explain the difference between them. If interviewer is
still not satisfied, you’ll have to explain the whole kitchen behind the scenes,
including a difference between local server and inproc server, meaning and
mechanism of class factory, etc. You may also mention other methods of
object creation like CoGetInstanceFromFile, but discussion will likely turn to
discussion of monikers then.
What happens when client calls CoCreateInstance?
Again, all depends on the level of detail and expertise of interviewer. Start
with simple explanation of class object and class factory mechanism. Further
details would depend on a specific situation.
What the limitations of CoCreateInstance?
Well, the major problems with CoCreateInstance is that it is only able to create
one object and only on local system. To create a remote object or to get
several objects, based on single CLSID, at the same time, one should use
CoCreateInstanceEx.
What is ag