I haven't used c++ much in years, and have no experience with using COM from c++. I've written some code in c# using Office interop to work with Word, Excel, and PowerPoint, but am struggling to port that to c++. I've found Office Automation Using Visual C++, which isn't super helpful. It describes 3 ways to do it:
with the #import directive (which it calls buggy and discourages), with MFC, or with pure c++.
The code sample for pure c++ is extremely old-school, and looks to have been written at least 15 years ago. And instead of coding against a strongly-typed interface, it does everything with strings and variants.
I'm trying to do the best of all worlds, the clean code of MFC, but in a modern c++/winrt environment, with smart pointers, etc. In c# for example, I can do:
Windows.Win32.PInvoke.CLSIDFromProgIDEx("Word.Application", out Guid clsid);
Word.Application app = Windows.Win32.PInvoke.GetActiveObject(clsid, null, out object obj) as Word.Application;
app.Activate();
In c++ I have:
CLSID clsid;
check_hresult(CLSIDFromProgID(L"Word.Application", &clsid));
com_ptr<::IUnknown> unk;
check_hresult(GetActiveObject(clsid, NULL, unk.put()));
But then how do I actually convert it to the interface?