You can also use templates (traits), if you need to statically "attach" a guid to the interface. Consider:
In a common h-file you create an empty unspecialized template:
template<typename TInterface> struct TInterfaceTraits {}
When defining your interface, write a template specialization for it (or you can write it in any other place including just before usage):
class ICalculator : public IUnknown
{
//...
};
template<> struct TInterfaceTraits<class ICalculator > {
static GUID guid() {
return IID_ICalculator ;
}
};
Then to get it's uuid you can write something like:
ICalculator *pCalcFace;
pObject->QueryInterface(TInterfaceTraits<ICalculator>::guid(), (void**)pCalcFace);
Of cause you can write (I leave it to you) a template wrapper to QueryInterface, which will use the traits to automatically supply proper guid, and that will be even easier to use, i.e.
ICalculator *pCalcFace = QueryInterface<ICalculator>(pObject);