CMyComPtrpObj; //Creating an object pointer HRESULT hr = pObject->QueryInterface(IID_IMyCustomInterface, (void**)&pCustomInterface); //Querying for a particular custom interface if(SUCCEEDED(hr)) { //Code to use the custom interface }
CMyComPtrIn both these examples, CMyComPtr QueryInterface is used to query a specific COM interface pointer using a particular object pointer. The function returns a HRESULT that indicates whether the query was successful or not. If it is successful, the pointer to the desired interface can be used to call its methods. CMyComPtr belongs to the ATL (Active Template Library) package library, which provides a set of C++ templates and functions to simplify the programming of COM objects in C++.pObj; //Creating an object pointer HRESULT hr = pObj->QueryInterface(IID_IAnotherInterface, (void**)&pAnotherInterface); //Querying for another interface if(SUCCEEDED(hr)) { //Code to use the another interface }