Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

The COM Threading Model and WIN2000

Hi,

I'm having a problem with the threading model in COM. I have a COM server 1 (exe server) that is multithreaded. A COM object of this server has to connect to another COM server 2 (also multithreaded exe server), but when I do CoInitializeEx(NULL, COINIT_MULTITHREADED), before entering this COM server 2, I keep on getting a COM error (Cannot change thread mode after it is set).
I only have this problem when I run the servers on WIN2000, on NT4, everything works fine.
Is there a difference between WIN2000 and NT4????

thanks for the help
Veerle
0
veede
Asked:
veede
1 Solution
 
ambienceCommented:
An exe server must do CoInitialize for itself after its made to run. Do you mean CoInitializeEx in server2 is failing ?
0
 
veedeAuthor Commented:
The COM exe server1 starts without any problems => there the CoInitializeEx works fine. But I can't do an CoInitializeEx before entering an object of server1( this is done in an interface class dll called by an ATlobject of server1 ).
0
 
veedeAuthor Commented:
Previous comment was wrong, I'm sorry!

The COM exe server1 starts without any problems => there the CoInitializeEx works fine.
But I can't do an CoInitializeEx before entering an object of server2(!!) (this is done in an interface class dll called
by an ATlobject of server1 ).
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ambienceCommented:
Put the CoInitializeEx inside Exe server2, as i said an exe server enters an apartment itself by calling CoInitialize etc.


0
 
veedeAuthor Commented:
Thanks, but there is also an CoInitializeEx() inside the exe server. I suppose that is no problem to do it twice (and you should if the server and the user of the server are in different threads).
In fact I have the problem that if I do a CoInitializeEx(NULL, COINIT_MULTITHREADED) or a CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) inside an ATLobject of server1, I ALWAYS get ComError "Cannot change thread mode after it is set" ????? And I only have this problem in WIN2000????
0
 
mironCommented:
check if the macro
#define _WIN32_WINNT     0x0400
in the file stdafx.h is uncommented.

my 2 cents
0
 
ambienceCommented:
>>I suppose that is no problem to do it twice

I have doubts regarding that,  had some rather weird experiences with that but those were on Win9x and guess what the same code worked on WinNT 4.0.

>> you should if the server and the user of the server are in different threads).

Only a thread that has not already entered an apartment, should call CoInitialize*** to enter an apartment. If your exe server has multiple threads then each thread should call CoInit.. to enter an apartment.

Try commenting out redundant CoInit calls and seee if it works.
0
 
veedeAuthor Commented:
thanks for the help,
but i found the problem (don't know what's the cause): if I define connections points in my ATLobject, if have the problem I discribed (only in win2000). If I don't click "Use Connection Points" in the ATLObject Wizard of Visual Studio, it works fine.

0
 
griesshCommented:
Dear veede

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to

     "refund the points and PAQ at zero points"


PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
MindphaserCommented:
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now