Difference between CComPtr and CComQIPtr?

Top  Previous  Next

CComQIPtr is derived from CComPtr. QI stands for Query Interface. When you construct with a CComQIPtr it can result in nullptr., which means the cast has not worked. This is useful to check the type of the pointer. For example:


   CComQIPtr<PartDocument> pPartDoc(pDoc) ;

   if (pPartDoc == nullptr) {

       // pDoc did not point to a PartDocument

       return (false) ;



...and another example...


   CComQIPtr<AssemblyDocument> pAsmDoc(pDoc);

   if (pAsmDoc == nullptr) {

       // pDoc did not point to an AssemblyDocument

       return (nullptr) ;




Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)