WINNT 4.0 service program

WINNT 4.0 service program

I am running into some trouble understanding what is required to use the ADVAPI32 function: StartServiceCtrlDispatcher(..)

The arguement to the routine is a service table entry type. Which I believe is 2 integer pointer types. The first is a pointer to a character string(C string) containing the name of the service as defined in the service control managers table(I have successfully gotten the service definition setup in the SCM). The second is a pointer to the subroutine that will perform the actual services.

My application is failing with memory access violations.
Here is a bit of the application code:
PROGRAM schedtest

USE DFWINTY
USE ADVAPI32

INTEGER(BOOL) SSCDispatcher
TYPE(T_SERVICE_TABLE_ENTRY) ServiceStartTable
CHARACTER*10 PROG
EXTERNAL SCHEDSTART
INTEGER*4 PP
POINTER(PP,SCHEDSTART)

DATA PROG/'testsch01'C/

ServiceStartTable%lpServiceName = LOC(PROG)
ServiceStartTable%lpServiceProc = PP
OPEN(15,FILE='C:TEMPSERVICE.DAT',ACCESS='APPEND', IOSTAT=IER,
& FORM='FORMATTED',STATUS='UNKNOWN')
IF(IER .EQ. 0)THEN
WRITE(15,*)' GOT TO THE main ROUTINE'
CLOSE(15)
ENDIF

SSCDispatcher = StartServiceCtrlDispatcher(ServiceStartTable)
IF(.NOT. SSCDispatcher)THEN !PROBLEM
OPEN(15,FILE='C:TEMPSERVICE.DAT',ACCESS='APPEND', IOSTAT=IER,
& FORM='FORMATTED',STATUS='UNKNOWN')
IF(IER .EQ. 0)THEN
WRITE(15,*)' error at 1'
CLOSE(15)
ENDIF
ENDIF

STOP
END

SUBROUTINE SCHEDSTART(PARGCOUNT, PARGDATA)
USE DFWINTY
USE ADVAPI32
USE DFLIB, ONLY: SLEEPQQ
INTEGER*4 START,CRATE, MAXC, WAIT, RTIME, FINISH
LOGICAL RUN
INTEGER*4 PARGCOUNT, PARGDATA, SERVSTATHANDLE !POINTERS
TYPE(T_SERVICE_STATUS) SCHEDSTATUS
INTEGER(BOOL) SSSTATUS
EXTERNAL SCHEDHANDLER
INTEGER*4 PP !POINTER ????TRYING THIS
POINTER(PP,SCHEDHANDLER)
COMMON /CONTROLS/ RUN, SERVSTATHANDLE, SCHEDSTATUS

OPEN(15,FILE='C:TEMPSERVICE.DAT',ACCESS='APPEND', IOSTAT=IER,
& FORM='FORMATTED',STATUS='UNKNOWN')
IF(IER .EQ. 0)THEN
WRITE(15,*)' GOT INTO THE SCHEDSTART ROUTINE'
CLOSE(15)
ENDIF
SCHEDSTATUS%dwServiceType = SERVICE_WIN32_OWN_PROCESS
SCHEDSTATUS%dwCurrentState = SERVICE_RUNNING
SCHEDSTATUS%dwControlsAccepted = SERVICE_ACCEPT_STOP
SCHEDSTATUS%dwWin32ExitCode = 0
SCHEDSTATUS%dwServiceSpecificExitCode = 0
SCHEDSTATUS%dwCheckPoint = 0
SCHEDSTATUS%dwWaitHint = 0

SERVSTATHANDLE = RegisterServiceCtrlHandler('UOPSCHED'C,
& PP)
IF(SERVSTATHANDLE .EQ. 0)THEN !PROBLEM

ENDIF

SSSTATUS = SetServiceStatus(SERVSTATHANDLE, SCHEDSTATUS)

I suspect that pointer to the service main routine is invalid, any ideas on how to pass this routine name in that structure as required?

A C++ programmer has also advised that the arguement to the startservicectrldispatcher is supposed to be a pointer to an array of pointers ending in two null values....any comments on
this or how to implement?

Thanks
Steve
your text hereyour text hereyour text hereyour text here

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Note that your program appears truncated, you might try attaching it using this forum. Anyhow regarding the routine pointer, eliminate the POINTER statment and PP variable and just use LOC(procedurename).

James

Thanks for the help, that change made it operational.

Steve

Leave a Comment

Please sign in to add a comment. Not a member? Join today