ComObjPtrpSomeObj; HRESULT hr = CoCreateInstance(CLSID_SomeClass, NULL, CLSCTX_ALL, IID_ISomeInterface, (void**)&pSomeObj); if (SUCCEEDED(hr)) { // use pSomeObj to access the methods and properties of the COM object } else { // handle the error }
ComObjPtrIn this example, a copy of the ComObjPtr object pSomeObj1 is created and assigned to pSomeObj2. Both ComObjPtr objects now share the same underlying COM object, and the reference count for the COM object is incremented. These examples use the ComObjPtr class template from the Microsoft Foundation Classes (MFC) library, which is a package library for building Windows-based applications using C++.pSomeObj1; // create and initialize pSomeObj1 ComObjPtr pSomeObj2 = pSomeObj1;