CComPtrpXmlDoc; HRESULT hr = CoCreateInstance(__uuidof(DOMDocument), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pXmlDoc)); if (FAILED(hr)) { // Handle error } // Use the XML document object
CComPtrIn this example, the `SHGetDesktopFolder` function is used to retrieve a pointer to the Windows desktop folder as a COM object. A CMyComPtr object is created for the IDesktopFolder interface, and the `QueryInterface` method is used to retrieve the IShellFolder interface from the desktop folder object. Package/library: ATL (Active Template Library) is a set of C++ template classes for simplifying the development of COM-based applications in Windows. CMyComPtr is a part of the ATL library.pShellFolder; CComPtr pDesktopFolder; // Get a pointer to the desktop folder SHGetDesktopFolder(&pDesktopFolder); // Query the desktop folder interface for the shell folder interface HRESULT hr = pDesktopFolder->QueryInterface(IID_PPV_ARGS(&pShellFolder)); if (FAILED(hr)) { // Handle error } // Use the shell folder object