Software & Finance





VC++ ATL/COM - Step 3.1 Adding a COM Interface - Threading Model





 

3.1 Threading Model

Single: Specifies that the object always runs in the primary COM thread. STA and COM InprocServer32 will come under this category.

 

Apartment: It is a single thread apartment and is tied to a specific thread and has a Windows message pump (default).

 

Both:  (both STA and MTA)

 Specifies that the object can use STA(single thread apartment) or MTA (Mutli-thread apartment ) model

 

Free: (MTA)

 Specifies that the object uses free threading equivalent to a multithread apartment model.

 

Now look at the code created for MathControl Object

 

class ATL_NO_VTABLE CMathControl :

      public CComObjectRootEx<CComSingleThreadModel>,

      public CComCoClass<CMathControl, &CLSID_MathControl>,

      public IDispatchImpl<IMathControl, &IID_IMathControl,            

            &LIBID_SFTComServerLib, 1, 0>

 

 

From the above, we know the it uses STA - CComSingleThreadModel. If we have chosen Free threading model, then you can find the class with CComMultiThreadModel.

 Click here to download the complete source code of COM DLL Server, C++ Client and CSharp Client