Environment:
I have a JNI program which is made of the following pieces
The generated DLL is kept in the bin folder inside JDK directory
Issue: When I run the program, I get an error msg in the C++ program that CoInitializeEx failed with the error code 0x80010106.
following is the line where the program fails.
hres = CoInitializeEx(0,COINIT_MULTITHREADED).
I tried increasing the heapSize still it continues to fail.
Any particular reason why CoInitializeEx is failing?
Thanks in advance
The error 0x80010106 means "HRESULT - 0x80010106 - Cannot change thread mode after it is set."
The problem is basically that a thread can Initialize its COM mode (and apartment type, STA/MTA) only once. Once it is set, you will get this error if you attempt to initialize again with a different value.
Often what happens with this error is that some other 3rd-party code will cause COM to become initialized before your code is executed. If this is the case, then you have a couple of choices:
1) Try to find a way to have your code execute first, so you can set the COM apartment type yourself. This can be tricky, and might cause side effects if the 3rd-party code expects an STA
2) Put your code on its own thread, where you can explicitly set the apartment type
If you actually don't care about the apartment type, then you can just change the call to CoInitializeEx to use COINIT_APARTMENTTHREADED (STA) instead of COINIT_MULTITHREADED (MTA).
Hope that helps,
John
User contributions licensed under CC BY-SA 3.0