Solved

The COM Threading Model  and WIN2000

Posted on 2002-05-17
10
398 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 22

Expert Comment

by:ambience
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:miron
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now