Interface is a collection of function definitions to access a COM class. C++ way to define an interface is a class with one or more pure virtual functions.

class interface ICalculate : public IDispatch
  virtual HRESULT __stdcall Operand1(long *pVal) = 0;
  virtual HRESULT __stdcall Operand1(long newVal) = 0;
  virtual HRESULT __stdcall Operand2(long *pVal) = 0;
  virtual HRESULT __stdcall Operand2(long newVal) = 0;
  virtual HRESULT __stdcall DoOperation(char operation) = 0;
  virtual HRESULT __stdcall Result(long *pVal) = 0;

An interface should have an unique GUID and name. Interface is generally defined using interface definition language in an IDL file.

  helpstring("ICalculate Interface tiny calculator demo opject"),
interface ICalculate : IDispatch
  [propget, id(1), helpstring("Operand1 of calculator")] HRESULT Operand1([out, retval] long *pVal);
  [propput, id(1), helpstring("Operand1 of calculator")] HRESULT Operand1([in] long newVal);
  [propget, id(2), helpstring("Operand2 of calculator")] HRESULT Operand2([out, retval] long *pVal);
  [propput, id(2), helpstring("Operand2 of calculator")] HRESULT Operand2([in] long newVal);
  [id(3), helpstring("calculator main Operation method")] HRESULT DoOperation([in] char operation);
  [propget, id(4), helpstring("Result of calculator")] HRESULT Result([out, retval] long *pVal);


Co-Classes are the component class implemented in com server. Co class can have multiple interfaces implemented in it. There will be at least one default interface. Interface methods and properties are used to access a co-class. Co-class should have a name and unique GUID.

library MATHLIBLib

    helpstring("Calculate Class")
  coclass Calculate
    interface ICalMode;
    [default] interface ICalculate;

About our authors: Team EQA

You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.