calling COM from 2 threads
-
Hi, I have an ATL COM that is initialized with CoInitializeEx(NULL,COINIT_MULTITHREADED) thus its multiple apartment COM and calls can be made simultaneously from different clients. When I initialize and call it from an application, no problem. When I initialize and call from 2 different applications- no problem as well. But when I initialize it in one application and then try to initialize or call it from another thread in the same application, I get the following error: "the application called an interface that was marshaled for a different thread" What can I do to solve it? Should I change the way I call it? Thanks. avivhal
-
Hi, I have an ATL COM that is initialized with CoInitializeEx(NULL,COINIT_MULTITHREADED) thus its multiple apartment COM and calls can be made simultaneously from different clients. When I initialize and call it from an application, no problem. When I initialize and call from 2 different applications- no problem as well. But when I initialize it in one application and then try to initialize or call it from another thread in the same application, I get the following error: "the application called an interface that was marshaled for a different thread" What can I do to solve it? Should I change the way I call it? Thanks. avivhal
the
CoInitialize(Ex)
initializes the apartment for the thread - you also need to mark the type of apartment for the object. If you create it in ATL, the wizard asks you if you want to create single/multithreaded object. You need to have Free threaded object and free threaded thread to achieve no marshalling. -
Hi, I have an ATL COM that is initialized with CoInitializeEx(NULL,COINIT_MULTITHREADED) thus its multiple apartment COM and calls can be made simultaneously from different clients. When I initialize and call it from an application, no problem. When I initialize and call from 2 different applications- no problem as well. But when I initialize it in one application and then try to initialize or call it from another thread in the same application, I get the following error: "the application called an interface that was marshaled for a different thread" What can I do to solve it? Should I change the way I call it? Thanks. avivhal