Board index » delphi » Automation object in NT Service

Automation object in NT Service

I've written a service application for NT, which worked fine until I tried
to add a COM automation object to it.  Now, the service can't start -
Windows NT reports that the service is not responding to control
messages (after a long delay).

I have found that if I comment out the line in the initialization section
of the unit containing the TAutoObject descendant, the service works OK
again.  That is, if I don't create the TAutoObjectFactory object the
service can still start.  Obviously, this isn't much use because OLE
Automation client applications can't create instances of my automated
object if the TAutoObjectFactory is not instantiated.

Does anyone know what's going on here?  Is it possible for an NT service
written with the Delphi 4 NT Service wizard to also be an OLE Automation
server? How can I fix this? I need to provide a solution fairly urgently,
so if anyone knows anything about this, could you please let me know?

Thanks,

Michael Collas

 

Re:Automation object in NT Service


In article <6ve54v$it...@emu.cs.rmit.edu.au>, mcol...@yallara.cs.rmit.edu.au
says...

Quote

>I've written a service application for NT, which worked fine until I tried
>to add a COM automation object to it.  Now, the service can't start -
>Windows NT reports that the service is not responding to control
>messages (after a long delay).

>I have found that if I comment out the line in the initialization section
>of the unit containing the TAutoObject descendant, the service works OK
>again.  That is, if I don't create the TAutoObjectFactory object the
>service can still start.  Obviously, this isn't much use because OLE
>Automation client applications can't create instances of my automated
>object if the TAutoObjectFactory is not instantiated.

I'm no service expert, but found the following in the win32 help file:

A ServiceMain function should perform the following tasks:

1. Call the RegisterServiceCtrlHandler function immediately to register a
Handler function to handle control requests for the service. The return value
of RegisterServiceCtrlHandler is a SERVICE_STATUS_HANDLE type that identifies
the service in calls to the SetServiceStatus function. A service calls
SetServiceStatus to inform the service control manager of its status.

2. Perform initialization. If the execution time of the initialization code is
expected to be very short (less than one second), initialization can be
performed directly in ServiceMain.

If the initialization time is expected to be longer than one second, call
SetServiceStatus, specifying SERVICE_START_PENDING as the current service
state. As initialization continues, the service should make additional calls to
SetServiceStatus to report progress. Sending multiple SetServiceStatus calls is
useful for both service debugging and product support.

It seems that your object creation takes too long, and that you must set the
service's state to SERVICE_START_PENDING before a timeconsuming initialization.
Hope this helps.

--
Christo Crause
Thermal Separations Research
University of Stellenbosch
South Africa

Other Threads