Solved

The COM Threading Model  and WIN2000

Posted on 2002-05-17
10
413 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

628 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