One way is to use the #import
directive and use the native C++ compiler COM support classes instead of ATL (such as _com_ptr_t<>
).
Your code then boils down to 2 lines of code:
MSHTML::IHTMLElement2Ptr element;
MSHTML::IHTMLRectPtr rect = element->getBoundingClientRect();
RECT rc = { rect->left, rect->top, rect->right, rect->bottom };
Import the mshtml stuff like this:
#pragma warning(push)
// warning C4192: automatically excluding '<xyz>' while importing type library 'mshtml.tlb'
#pragma warning(disable: 4192)
#import <mshtml.tlb>
#pragma warning(pop)
All the boiler-plate code is hidden because #import
automatically creates property wrappers and methods doing HRESULT checking.