Keeping OLE server running after client terminated

Peter Allin wrote:

> I'm working on a project using OLE automation to control MS Word 95.
> In some situations i want my program to start Word, do something to
> the Word document, then terminate and keep Word running.
> But when Word doesn't have any more clients to service it shuts down
> automatically.

> Does anyone know how to prevent this?

> Peter Allin.

One basic part of the COM architecture is how it's lifetime is
controlled by reference counting. If this count goes to zero, then the
created object is released (destroyed). You can increase the count by
using _AddRef, decrease with _Release. Some language implementations,
like Object Pascal in Delphi, automatically takes care of calling
_AddRef/_Release for you, therefor it may not be something you use very

_AddRef can be used directly, but the count should be decremented
(_Release) at some point. After your application has gone bye bye,
what's controlling the object's lifetime?

Another alternative, if you origanally built the server, is to...
1. Add an option to the server's property sheet allowing shutdown.
2. The instance should be represented on the desktop, like the
notification bar. Access to the property sheet could be performed by
clicking on it's icon.
3. If you leave the thing running without clients (ie ref count = 1),
then re-connect (ie ref count = 2), then  leave again( dec to 1), you
should give the user or programmer the opportunity to shutdown the

Another "type" of client could do many of the same things and be used as
a controller of server lifetime.