Mar 9, 2010

COM Basics - Important Points

COM
===

IUNKNOWN

1)Base interface of COM. Every interface directly or indirectly derived from this interface
2)Provides three methods AddRef, QueryInterface, Release
3)AddRef increments the reference count to the object
4)Release decrements the reference count to the object
5)QueryInterface obtains Pointer to the object.
6)QueryInterface returns E_NOINTERFACE if requested object was not found and also nullify its out parameter.

IDISPOSE

1)exposes objects, methods and properties to programming tools and other applications that support Automation.
2)The object's properties and methods can be accessed using IDispatch::GetIDsOfNames and IDispatch::Invoke.

CoCreateInstance and CoCreateInstanceEX

1)CocreateInstance is used to create object in local system and it allows only one object to create at a time.
2)CoCreateInstanceEx is used to create object in remote system and it allows to create multiple objects based on single CLSID

Aggregation

1)Is the mechanism in which outerobject exposes the methods of inner object
2)We can get a pointer to the inner interface, calling QueryInterface of the outer object with IID of the inner interface.

Moniker

1)An object that implements IMoniker interface.
2)provides information to uniquely identify a COM object.

OLE vs COM

1)OLE is build on top of COM
2)COM is a specification, while OLE is a particular implementation of this specification

COM vs DCOM

1)introduced several improvements for distributed environment, such as MULTI_QI (multiple QueryInterface()), security

contexts
2)DCOM demonstrated importance of surrogate process (you cannot run in-proc server on a remote machine).
3)DCOM introduced a load balancing
4)DCOM extends COM

Dual Interface

1) which supports both IDISPATCH and V-Table based interfaces
2)You may have two dual interfaces in one class. you cannot work with two dual interfaces at the same time.

Marshalling By Value

1) Instead of accessing 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.
2) not involve network round trips.

multi-threaded apartment (MTA) and Single-threaded apartment (STA)

1) In STA, all calls will be made by the same thread. In MTA, COM object can be accessed by many threads simultaneously
2) A process can have only one MTA, but many STAs

In-Proc means 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.

IDL

Interface Definition Language to describe COM interfaces

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.

2 comments:

  1. Regsvr32.exe is a five-step process to register or unregister DLLs or OCXs. The process, in order, is:

    1. Oleinitialize
    2. LoadLibrary to load the DLL
    3. DllRegisterServer or DllUnregisterServer
    4. FreeLibrary
    5. OleUnitialize

    ReplyDelete
  2. The ATL COM object wizard supports the following threading options:

    Single: Similar to single threading, which existed during the Windows 3.1 days. It permitted creation of only one thread at a time.

    Apartment: Similar to the STA (Single-Threaded Apartment) model.

    Both: Similar to the Mixed-Threading model.

    Free: Similar to the MTA (Multi-Threaded Apartment) model.

    COM currently supports the 4 threading models shown above.

    ReplyDelete