HRESULT __stdcall CCOM_OBJECT::QueryInterface(const IID &iid,
void **iface)
{
// this function basically casts the this pointer or the IUnknown
// pointer into the interface requested, notice the comparison with
// the GUIDs generated and defined in the beginning of the program
// requesting the IUnknown base interface
if (iid==IID_IUnknown)
{
cout << “Requesting IUnknown interface” << endl;
*iface = (IX*)this;
} // end if
// maybe IX?
if (iid==IID_IX)
{
cout << “Requesting IX interface” << endl;
*iface = (IX*)this;
} // end if
else // maybe IY
if (iid==IID_IY)
{
cout << “Requesting IY interface” << endl;
*iface = (IY*)this;
} // end if
else
{ // cant find it!
cout << “Requesting unknown interaface!” << endl;
*iface = NULL;
return(E_NOINTERFACE);
} // end else
// if everything went well cast pointer to
// IUnknown and call addref()
((IUnknown *)(*iface))->AddRef();
return(S_OK);
} // end QueryInterface