COM Interview Questions: Object? Aggregation Is The Reuse Mechanism, in Which The Outer Object Exposes
COM Interview Questions: Object? Aggregation Is The Reuse Mechanism, in Which The Outer Object Exposes
Introduction
dim d1 as IDualInterface1
dim d2 as IDualInterface2
set d1 = new MyClassWithTwoDuals
set d2 = d1
14. What is marshalling by value? Some objects can essentially be considered static:
regardless of which methods are called, the state of the object does not change.
Instead of accessing such an object remotely, it is possible to copy the static state of
the object and create a new object with the same state information on the caller
side. The caller won�t be able to notice the difference, but calls will be more
efficient because they do not involve network round trips. This is called �marshaling
by value�.
15. What is a multi-threaded apartment (MTA)? Single-threaded apartment
(STA)? This is pretty difficult question to describe shortly. Anyway, apartments were
introduced by Microsoft in NT 3.51 and late Windows 95 to isolate the problem of
running legacy non-thread safe code into multithreaded environment. Each thread
was �encapsulated� into so called single-threaded apartment. The reason to create
an object in apartment is thread-safety. COM is responsible synchronize access to
the object even if the object inside of the apartment is not thread-safe.
Multithreaded apartments (MTA, or free threading apartment) were introduced in NT
4.0. Idea behind MTA is that COM is not responsible to synchronize object calls
between threads. In MTA the developer is responsible for that. See �Professional
DCOM Programming� of Dr. Grimes et al. or �Essential COM� of Don Box for the
further discussion on this topic.
16. Let�s assume we have object B and aggregated object C (in-proc server),
created by B. Can you access any interface of B from C? What�s the
difference between aggregated and contained objects? Yes, you can. This is
fundamental postulate of COM: �If you can get there from here, you can get there
from anywhere�, i.e. QI�ing for IUnknown you may proceed and to get a pointer to
any other interface, supported by the object. Aggregated object exposes its interface
directly, without visible intervention of the object container. Contained object is
created within the object container and its interfaces might be altered or filtered by
the object container.
17. What is ROT ? GIT ? Count pros and cons of both. By definition, running object
table (ROT) is a globally accessible table on each computer that keeps track of all
COM objects in the running state that can be identified by a moniker. Moniker
providers register an object in the table, which increments the object�s reference
count. Before the object can be destroyed, its moniker must be released from the
table. Global Interface Table (GIT) allows any apartment (either single- or multi-
threaded) in a process to get access to an interface implemented on an object in
any other apartment in the process.
18. If you have an object with two interfaces, can you custom marshal one of
them? No! The decision to use custom marshaling is an all-or-nothing decision; an
object has to custom marshal all its interfaces or none of them.
19. Is there a way to register in-proc server without regsvr32.exe? Yes. Call
DllRegisterServer() from the client. Do not forget to call DLLUnregisterServer() from
the same client. You may also use Registrar object for the same purpose or use
direct manipulation of the windows registry.
20. What is VARIANT? Why and where would you use it? VARIANT is a huge union
containing automation type. This allows easy conversion of one automation type to
another. The biggest disadvantage of VARIANT is size of the union.
21. How can you guarantee that only remote server is ever created by a client?
Create an object (call CoCreateObjectEx()) with CLSCTX_REMOTE_SERVER flag.
22. What is __declspec(novtable)? Why would you need this? __declspec(novtable)
is a Microsoft�s compiler optimization. The main idea of this optimization is to strip
the vtable initialization code from abstract class (for abstract class the vtable is
empty, while it is initialized in contructor)
23. What is an IDL? IDL stands for Interface Definition Language. IDL is the language
to describe COM interfaces.
24. What is In-proc? In-proc is in-process COM object, i.e. COM object that
implemented as DLL and supposed to be hosted by a container. When you have to
instantiate the in-proc object remotely, you may use DLLHost.exe application that
was design specially for this purpose.
25. What is OLE? OLE is an object and embedding first implementation of COM spec
available from MS before COM was officially named COM.
26. Give examples of OLE usage. The most famous examples are probably drag and
drop and structured storage implementations.
27. What are 2 storage types for composite document? Storage and Stream.
28. Is .doc document a compound document? Is it a structured storage?
Compound document is a document that contains information about other
documents hosted in this document. All office documents _may_ be compound
documents, but may be not. Word documents from version 6.0 and up are stored as
structured storage.