Solved

The COM Threading Model  and WIN2000

Posted on 2002-05-17
10
409 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
Industry Leaders: 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 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