Click here to Skip to main content
15,868,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a com local server(an BitManipulater.exe server) and a client.I executed two instances of client programs in debug mode.If i open the task manager in windows xp, the processes tab is showing only one BitManipulater.exe process.How com deals with local server, if lot of client are using same local server.I thought there will be two instances of BitManipulater.exe.Any explanation on this please,

Thanks in advance,
venkatanarayana
Posted

It can work either way. The server can control whether a single instance or multiple instances are used by setting flags when it calls the CoRegisterClassObject[^] function. Using REGCLS_SINGLEUSE (see REGCLS[^]) will results in multiple instances while REGCLS_MULTIPLEUSE result in the same instance being reused.

If you're using MFC look at the code in the server's InitInstance function. You'll find some which looks like this:
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
	IDR_MFCEXETYPE,
	RUNTIME_CLASS(CMFCExeComServerDoc),
	RUNTIME_CLASS(CChildFrame), // custom MDI child frame
	RUNTIME_CLASS(CMFCExeComServerView));
AddDocTemplate(pDocTemplate);

// Connect the COleTemplateServer to the document template.
//  The COleTemplateServer creates new documents on behalf
//  of requesting OLE containers by using information
//  specified in the document template.
m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);


Change the underlined bit to TRUE and separate instances will be used.
 
Share this answer
 
v10
vasuvasanth wrote:
I thought there will be two instances of BitManipulater.exe

Why did you think so? For an out-of-process server this behaviour (one instance) looks appropriate to me.
:)
 
Share this answer
 
Comments
Stephen Hewitt 9-Jun-10 23:55pm    
Reason for my vote of 2
Clearly both behaviours have their uses and there are also cases which could force your hand.

Single instance:
GOOD: Since only a single process is used it may be more efficient.
BAD: A fault in one server object could crash the process and will effect all clients.

Multiple instance:
GOOD: Faults in one server object that causes a crash only effects one client.
BAD: Multiple processes mean more system resources are used.

Things that could force your hand:
- If you're using a library that has global (per process) settings and you want each instance of the object to be able to use different settings. In this case you're forced to the use separate instances model.

CPallini 10-Jun-10 3:25am    
In the case of Multiple instances, why cannot we use a in-process server?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900