Try calling OleInitialize( ) at the beginning of fn.
Or call CoInitializeEx(NULL, COINIT_APARTMENTTHREADED).
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
MS Office interop API working when called within the class containing Addin OnConnection method. But when i call the same API from another thread, it fails with some unknown exception.
Read in few forum pages that Office automation is Single-threaded.
Any way to override this behaviour? Few people in few forums mentioned about using IMessageFilter, but i can't figure it out about using it in C++.
Please guide. Here is some sample code.
CComQIPtr<Word::_Application> pWordApp;
CComQIPtr<Word::Windows> spWindows;
DWORD WINAPI fn(LPVOID lpParam)
{
pWordApp->get_Windows(&spWindows); //////// not working, some exception is raised
}
class ATL_NO_VTABLE CConnect :
{
public:
STDMETHOD(OnConnection)(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY** custom)
{
pWordApp = Application;
pWordApp->get_Windows(&spWindows); ////// working
CreateThread(NULL, 0, fn, NULL, 0, NULL);
}
}
Try calling OleInitialize( ) at the beginning of fn.
Or call CoInitializeEx(NULL, COINIT_APARTMENTTHREADED).