My DLL using COM objects with COINIT_MULTITHREADED is no more working on Python 3.7

0

I'm using a C++ DLL with python which makes use of COM objects. I'm loading it with cdll.LoadLibray.

My application was working fine with python 2.7. Now that I'm moving to Python 3.7 my C++ DLL fails when I call: CoInitializeEx(NULL,COINIT_MULTITHREADED) with error 0x80010106: Cannot change thread mode after it is set.

By googling a bit I found some references on sys.coinit_flags = pythoncom.COINIT_MULTITHREADED but this pieces of code does not solve the issue.

It seems Python 3 is initializing COM by itself and now I cannot change the COM concurrency model.

How can I enable COINIT_MULTITHREADED?

python
python-3.x
com
dynamic-dll-import
asked on Stack Overflow Jun 6, 2019 by cabbi

1 Answer

0

Ok... for whoever will have this issue, after googling and trying to understand how to get Python 3 not to initialize COM or initialize it for MTA (i.e. COINIT_MULTITHREADED) I gave up and simply put CoUninitialize() in my C++ code just before calling CoInitializeEx(NULL,COINIT_MULTITHREADED) needed by my DLL.

answered on Stack Overflow Jun 6, 2019 by cabbi

User contributions licensed under CC BY-SA 3.0