Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

The COM Threading Model  and WIN2000

Posted on 2002-05-17
10
405 Views
Last Modified: 2011-04-14
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
Comment
Question by:veede
10 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 7015714
An exe server must do CoInitialize for itself after its made to run. Do you mean CoInitializeEx in server2 is failing ?
0
 

Author Comment

by:veede
ID: 7015746
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
 

Author Comment

by:veede
ID: 7015749
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 22

Expert Comment

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


0
 

Author Comment

by:veede
ID: 7016098
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
 
LVL 9

Expert Comment

by:miron
ID: 7017488
check if the macro
#define _WIN32_WINNT     0x0400
in the file stdafx.h is uncommented.

my 2 cents
0
 
LVL 22

Expert Comment

by:ambience
ID: 7023157
>>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
 

Author Comment

by:veede
ID: 7027155
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
 
LVL 11

Expert Comment

by:griessh
ID: 7178788
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
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 7199792
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question