threading problems
-
I want to use my exe-server (attributed) in a MFC-application with several threads. In the main thread of the MFC-application I use smartpointers and CreateInstance to create an instance of the exe-server. By using CoInitializeEx(NULL, COINIT_MULTITHREADED) I get access to the server in every thread of my application. By using CoInitialize(NULL) just the main thread has access to the server, but that's clear. My Problem is, that if I use any ActiveX component in the application the threading model seems to be initialized automaticaly for single threading and calling CoInitialize is not possible anymore. Is there a solution for my problem ?
-
I want to use my exe-server (attributed) in a MFC-application with several threads. In the main thread of the MFC-application I use smartpointers and CreateInstance to create an instance of the exe-server. By using CoInitializeEx(NULL, COINIT_MULTITHREADED) I get access to the server in every thread of my application. By using CoInitialize(NULL) just the main thread has access to the server, but that's clear. My Problem is, that if I use any ActiveX component in the application the threading model seems to be initialized automaticaly for single threading and calling CoInitialize is not possible anymore. Is there a solution for my problem ?
The apartment is initialized for each thread once when you call CoInitInstance ( Ex). If you use COINIT_MULTITHREADED, you can pass around the interface ptr without any problems in any thread marked as MTA. Between threads with different apartments you must marshall the interface ( you can use CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream)