Software & Finance





VC++ ATL/COM - Step 3.3 Adding a COM Interface - Dual / Custom Interface





 

3.3 Dual / Custom Interface

Dual: Vtable has the following two important features:

          1. custom interface functions

          2. late binding IDispatch Interface

 

Custom: Vtable has only custom interface functions so that it can be faster and can only be accessed via c++ and can not be used with VB, Java or any other scripting language.

 

Using IDispatch and IUnknown interface 

The following lines does the magic for queryinterface 

BEGIN_COM_MAP(CMathControl)

      COM_INTERFACE_ENTRY(IMathControl)

      COM_INTERFACE_ENTRY(IDispatch)

END_COM_MAP()

 

If you have chosen Custom interface instead of Dual interface, the above lines COM MAP code  will look like the following: 

BEGIN_COM_MAP(CMathControl)

      COM_INTERFACE_ENTRY(IMathControl)

END_COM_MAP() 

The big difference here is there is no definition for IDispatch. 

[

      object,

      uuid(B129C4F7-81EA-47DA-AA22-4120C487C3FB),

      dual,

      nonextensible,

      helpstring("IMathControl Interface"),

      pointer_default(unique)

]

interface IMathControl : IDispatch{

};

 

[

      uuid(CEF82C0A-246B-4869-A44E-0707CCD480F7),

      version(1.0),

      helpstring("SFTComServer 1.0 Type Library")

]

library SFTComServerLib

{

      importlib("stdole2.tlb");

      [

            uuid(005C1FA1-FC7E-4FBB-8F12-15D410416F59),

            helpstring("MathControl Class")

      ]

      coclass MathControl

      {

            [default] interface IMathControl;

      };

};

 

I you have chosen custom interface, you will not find the dual keyword in idl definition and it will be derived from IUnknown.

 

[

      object,

      uuid(B129C4F7-81EA-47DA-AA22-4120C487C3FB),

      helpstring("IMathControl Interface"),

      pointer_default(unique)

]

interface IMathControl : IUnknown{

};

 

[

      uuid(CEF82C0A-246B-4869-A44E-0707CCD480F7),

      version(1.0),

      helpstring("SFTComServer 1.0 Type Library")

]

library SFTComServerLib

{

      importlib("stdole2.tlb");

      [

            uuid(005C1FA1-FC7E-4FBB-8F12-15D410416F59),

            helpstring("MathControl Class")

      ]

      coclass MathControl

      {

            [default] interface IMathControl;

      };

};

 

 

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