- 2


ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP |

SERVICE_ACCEPT_PAUSE_CONTINUE;

ServiceStatus.dwWin32ExitCode = 0;

ServiceStatus.dwServiceSpecificExitCode = 0;

ServiceStatus.dwCheckPoint = 0;

ServiceStatus.dwWaitHint = 0;

ServiceStatusHandle = RegisterServiceCtrlHandler(

TEXT("SiTime"),

ServiceCtrlHandler);

if (ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) {

/* Error Handling */

return;

}

// Initialization code goes here.

status = ServiceInitialization(argc,argv, &specificError);

// Handle error condition

if (status != NO_ERROR) {

ServiceStatus.dwCurrentState = SERVICE_STOPPED;

ServiceStatus.dwCheckPoint = 0;

ServiceStatus.dwWaitHint = 0;

ServiceStatus.dwWin32ExitCode = status;

ServiceStatus.dwServiceSpecificExitCode = specificError;

SetServiceStatus (ServiceStatusHandle, &ServiceStatus);

return;

}

// Initialization complete - report running status

ServiceStatus.dwCurrentState = SERVICE_RUNNING;

ServiceStatus.dwCheckPoint = 0;

ServiceStatus.dwWaitHint = 0;

if (!SetServiceStatus (ServiceStatusHandle, &ServiceStatus)) {

status = GetLastError();

}

// This is where the service does its work. //

ServerProcess();

return;

}

/* stub initialization function */

DWORD ServiceInitialization(DWORD argc, LPTSTR *argv,

DWORD *specificError)

{

*specificError = ServerInit();

if (*specificError) return *specificError;

return(0);

}

void WINAPI ServiceCtrlHandler ( IN DWORD Opcode)

{

DWORD status;

switch(Opcode) {

case SERVICE_CONTROL_PAUSE: