chsvlib
chsv helper source code
Auxiliary elements simplifying work with Windows API.

Helper directives used during a construction of COM interfaces

The directives provide ability to reduce amount of code needed to define a COM interface and classes that implement it. An example below shows using these definitions in order to define a pair of structures, where the Class1 structure defines the QueryInterface method inplace, and the Class2 structure declares the method inside its body and defines it in a separate implementation file.

Example code:

//Interface header
struct Class1:IUnknown, Interface1, Interface2
{
DEFINE_COM_QUERY_INTERFACE_ADD_ENTRY(Interface1_IID, Interface1)
DEFINE_COM_QUERY_INTERFACE_ADD_ENTRY(Interface2_IID, Interface2)
};
struct Class2:IUnknown, Interface1, Interface2
{
};
//Implementation source
DEFINE_COM_QUERY_INTERFACE_ADD_ENTRY(Interface1_IID, Interface1)
DEFINE_COM_QUERY_INTERFACE_ADD_ENTRY(Interface2_IID, Interface2)
#define DECLARE_COM_QUERY_INTERFACE
Definition: chsvwinutil.h:223
#define DEFINE_COM_QUERY_INTERFACE_ADD_ENTRY(iid_value, iface_type)
Definition: chsvwinutil.h:265
#define DEFINE_COM_QUERY_INTERFACE_BEGIN(classname)
Definition: chsvwinutil.h:250
#define DEFINE_COM_QUERY_INTERFACE_END
Definition: chsvwinutil.h:275
#define DECLARE_AND_DEFINE_COM_QUERY_INTERFACE_BEGIN
Definition: chsvwinutil.h:234
#define DECLARE_COM_QUERY_INTERFACE   virtual HRESULT __stdcall QueryInterface(REFIID refiid, void** ppv);
 
#define DECLARE_AND_DEFINE_COM_QUERY_INTERFACE_BEGIN
 
#define DEFINE_COM_QUERY_INTERFACE_BEGIN(classname)
 
#define DEFINE_COM_QUERY_INTERFACE_ADD_ENTRY(iid_value, iface_type)   else if (refiid == iid_value) *ppv = static_cast<std::remove_pointer_t<iface_type>*> (this);
 
#define DEFINE_COM_QUERY_INTERFACE_END   else {*ppv = NULL; return E_NOINTERFACE;} return S_OK;}
 

Detailed Description