I am trying to automate a certain scenario with MS-Word where I want to get the BeforePrint Event to get the filePath while print is initiated. The technology that is needed to get this done is COM C++. I initialize COM library by attaching to word process when it is initiated, by calling CoInitializeEx() with COINIT_APARTMENTTHREADED and things work. But when another application is launched which is doing something similar, for example, create pdf from word in Adobe Acrobat DC or any office addin which does something with BeforePrint event, the application/addin errors out with their functionality. My hunch is that something is wrong with the way COM is initialized since if I initialize COM by calling CoInitializeEx() with COINIT_MULTITHREADED everything seems to work fine.
Below are specific questions in this regards:
- What is different in calling CoInitializeEx() with COINIT_APARTMENTTHREADED vs COINIT_MULTITHREADED that makes it work in this scenario?
- With most samples online for COM C++ office automation for word, CoInitializeEx() is done with COINIT_APARTMENTTHREADED, what is the recommended way and why?
- Could there be issues for any other application/office addins if my application uses COINIT_MULTITHREADED for CoInitializeEx() instead of COINIT_APARTMENTTHREADED?
Links I have already referred but are not conclusive enough:
Source: Windows Questions C++