P2Pprogrammer 2 programmer

Home > Interview Question and Answer > COM, DCOM, MTS

COM, DCOM Interview Question and Answer

Interview question and answers for COM, DCOM, MTS. Interview question answers for COM objects. Interview question and answers for COM and OLE. Interview question and answers for creating COM component and using COM component.

Interview question and answers for COM, DCOM functions. Interview question and answers for COM marshalling , In process and Out process component, STA and MTA.

COM, DCOM Interview Question and Answers

1. What is IUnknown? What methods are provided by IUnknown?

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.

2. 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.

3. What should QueryInterface functions do if requested object was not found?

Return E_NOINTERFACE and nullify its out parameter.

4. How can would you create an instance of the object in COM?

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.

5. What happens when client calls CoCreateInstance?

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.

6. 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.

7. What is aggregation? How can we get an interface of the aggregated object?

Aggregation is the reuse mechanism, in which the outer object exposes interfaces from the inner object as if they were implemented on the outer object itself. This is useful when the outer object would always delegate every call to one of its interfaces to the same interface in the inner object. Aggregation is actually a specialized case of containment/delegation, and is available as a convenience to avoid extra implementation overhead in the outer object in these cases. We can get a pointer to the inner interface, calling QueryInterface of the outer object with IID of the inner interface.

8. C is aggregated by B, which in turn aggregated by A. Our client requested C. What will happen?

ueryInterface to A will delegate request to B which, in turn, will delegate request for the interface to C. This pointer will be returned to the client.

9. What is a moniker ?

An object that implements the IMoniker interface. A moniker acts as a name that uniquely identifies a COM object. In the same way that a path identifies a file in the file system, a moniker identifies a COM object in the directory namespace.

10. What’s the difference, if any, between OLE and COM?

OLE is build on top of COM. The question is not strict, because OLE was built over COM for years, while COM as a technology was presented by Microsoft a few years ago. You may mention also that COM is a specification, while OLE is a particular implementation of this specification, which in today’s world is not exactly true as well, because what people call COM today is likely implementation of COM spec by Microsoft.

11. What’s the difference between COM and DCOM?

Again, the question does not require strict answer. Any DCOM object is yet a COM object (DCOM extends COM) and any COM object may participate in DCOM transactions. DCOM introduced several improvements/optimizations for distributed environment, such as MULTI_QI (multiple QueryInterface()), security contexts etc. DCOM demonstrated importance of surrogate process (you cannot run in-proc server on a remote machine. You need a surrogate process to do that.) DCOM introduced a load balancing

12. What is a dual interface?

Dual interface is one that supports both - IDispatch interface and vtbl-based interface. Therefore, it might be used in scripting environment like VBScript and yet to use power and speed of vtbl-based interface for non-scripting environment. Discussion then may easily transform into analyzing of dual interface problems - be prepared to this twist.  

13. 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”.

14. 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.

Home > Interview Question and Answer > COM, DCOM, MTS