views:

698

answers:

6

I wrote an OLE automation server (using Delphi). I usually start the OLE server manually and use it as a normal application. From time to time I start a client, which automatically connect to the existing OLE Server.

When I terminate the client, the server does not terminate (at least when it was started manually before the client) but it won't accept any other OLE connection. Starting another client will trigger a new server instead of reusing the first one.

How can I reuse the same server with the second client?

(Question edited to reformulate it correctly. In the original version I was asking how to prevent the server from terminating, which wasn't a good formulation)

A: 

You should be able to increment the reference counter of the automation server when you start the server as a normal application. What you want to achieve is two-fold: Let the server not terminate when the client exits, and also let the server not terminate when you close your main form while the client is still running.

mghie
My question wasn't precise enough. I have now edited it.But thank you for the answer: It might be usefull in cases where I let the client start the server and I want to keep the server after closing the client.
Name
A: 

Create the COM object as Singleton. And also to keep the object running even after the Client goes, put extra reference count. To do this call QI once inside the COM object.

Vinay
+2  A: 

In the client, use

ConnectKind := ckRunningOrNew

and an existing server should be used instead of starting a new one.

Jim
Thank you for your answer, I wasn't aware of such a possibility. But it doesn't seem to work for me. Currently I'm testing with a client written in javascript (wsh) and I think I'm using a function which should work like this Delph setting, but it only works for the first client.
Name
Name: The information that not all clients are written in Delphi really belongs into the question, too.
Oliver Giesen
+1  A: 

There is a setting "Instancing" in the COM Object Wizard in Delphi. Allowed values are "internal", "Multiple Instance", "Single Instance".

I wanted to reuse the same COM server with multiple clients. That is why I chose "single Instance" and though that I would have a single instance of my server application for all the clients. But I was wrong. "Single Instance" means that there will be only one instance of a COM connection in my server. I should have chosen "Multiple Instance" to allow multiple COM connection (but one after the other, not simultaneous) in the same server.

I think that the words used in the COM Object Wizard in Delphi are not really clear. Instead of "multiple instance", "single instance", it would be better to have "multiuse" and "single use" like in this article about OLE Server and VB.

Name
A: 

A note about the previous post 'There is a setting "Instancing" in the COM Object Wizard in Delphi.' : At least in C++ builder, this option can simply be changed afterwards in the project settings, item "ATL". This item only appears there for an EXE-ole-server after you have added the first automation object to it.

(I have also asked author of This fine page to mention this in item 18.).

Grbts
A: 

You can also try changing the identity of the user that launches the OLE server, if it is an Exe and not a dll, by running dcomcnfg and choosing Component Services/Computers/My Computer/DCOM Config and selecting your server.

You might have to play around with it, I can't remember the differences between them all but I think "Interactive User" should do it.

Alan Clark