Determinazione dell'interfaccia supportata da un oggetto
Il metodo QueryInterface consente a un'applicazione di eseguire una query su un oggetto per determinare le interfacce supportate. L'applicazione di esempio imposta il puntatore ppv sull'interfaccia corrente.
STDMETHODIMP CAVIFileCF::QueryInterface(
const IID FAR& iid,
void FAR* FAR* ppv)
{
if (iid == IID_IUnknown)
*ppv = this; // set the interface pointer
// to this instance
else if (iid == IID_IClassFactory)
*ppv = this; // second chance to set the
// interface pointer to this
// instance
else
return ResultFromScode(E_NOINTERFACE);
AddRef(); //Increment the reference count
return NULL;
}