/*++ Copyright (c) 1991 Microsoft Corporation Module Name: ts3.c Abstract: This is a test program for exercising the service controller. This program acts like a service and exercises the Service Controller API that can be called from a service: SetServiceStatus StartServiceCtrlDispatcher RegisterServiceCtrlHandler Author: Dan Lafferty (danl) 2 Apr-1992 Environment: User Mode -Win32 Revision History: --*/ // // Includes // #include // DbgPrint prototype #include // DbgPrint prototype #include // needed for winbase.h #include #include #include #include #include // OpenFile #include // OpenFile #include // OpenFile #include // OpenFile #include // Unicode string macros #include // // Defines // #define INFINITE_WAIT_TIME 0xffffffff #define NULL_STRING TEXT(""); // // Globals // SERVICE_STATUS SingleStatus; HANDLE SingleDoneEvent; SERVICE_STATUS_HANDLE SingleStatusHandle; // // Function Prototypes // VOID SingleStart ( DWORD argc, LPTSTR *argv ); VOID SingleCtrlHandler ( IN DWORD opcode ); DWORD GetIntlFormat( LPWSTR type, LPWSTR string, DWORD numChars); VOID GetTime( LPWSTR *time ); /****************************************************************************/ VOID __cdecl main(void) { DWORD status; SERVICE_TABLE_ENTRY DispatchTable[] = { { TEXT("single"), SingleStart }, { TEXT("single1"), SingleStart }, // this entry should be ignored. { NULL, NULL } }; if (!StartServiceCtrlDispatcher( DispatchTable)) { status = GetLastError(); DbgPrint("[ts3]StartServiceCtrlDispatcher failed %d \n",status); if (status = ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { printf("Failed to connect to service controller, this " "program should be started with the Services Control Panel Applet, " "or at the command line with Net Start "); } } DbgPrint("[ts3]The Service Process is Terminating....)\n"); ExitProcess(0); } /****************************************************************************/ // // Single will take a long time to respond to pause // // VOID SingleStart ( DWORD argc, LPTSTR *argv ) { DWORD status; DWORD i; NETRESOURCEW netResource; DbgPrint(" [SINGLE] Inside the Single Service Thread\n"); for (i=0; i 0) { if (*czParseString == L'1'){ TwelveHour = FALSE; } } //----------------------------------------- // Is there a Leading Zero? //----------------------------------------- if (GetProfileIntW(L"intl",L"iTLZero",0) == 1) { LeadingZero = TRUE; } //----------------------------------------- // Get the Time Separator character. //----------------------------------------- numChars = GetIntlFormat(L"sTime",TimeSep,TIME_SEP_SIZE); if (numChars == 0) { // // No data, use the default. // TimeSep[0] = L':'; TimeSep[1] = L'\0'; } //------------------------------------------------- // If running a 12 hour clock, Get the AMPM string. //------------------------------------------------- if (TwelveHour) { if (SysTime.wHour > 11) { numChars = GetIntlFormat(L"s2359",czParseString,PARSE_SIZE); } else { numChars = GetIntlFormat(L"s1159",czParseString,PARSE_SIZE); } if (numChars > 0) { AMPMString = LocalAlloc(LMEM_FIXED,wcslen(czParseString)+sizeof(WCHAR)); if (AMPMString != NULL) { wcscpy(AMPMString,czParseString); } } } // // Build the time string // pTime = czTimeString + (wcslen(czTimeString) + 1); if ((TwelveHour) && (SysTime.wHour > 12)) { SysTime.wHour -= 12; } // // If the time is a single digit, and we need a leading zero, // than add the leading zero. // if ((SysTime.wHour < 10) && (LeadingZero)) { *pTime = L'0'; pTime++; } ultow(SysTime.wHour, pTime, 10); pTime += wcslen(pTime); *pTime = *TimeSep; pTime++; if (SysTime.wMinute < 10) { *pTime = L'0'; pTime++; } ultow(SysTime.wMinute, pTime, 10); wcscat(pTime,AMPMString); pTime = czTimeString + (wcslen(czTimeString) + 1); #ifdef CL_DEBUG printf("Time = %ws, Date = %ws\n",pTime,czTimeString); #endif *(--pTime) = L' '; printf("\n %ws\n", czTimeString); *time = czTimeString; } DWORD GetIntlFormat( LPWSTR type, LPWSTR string, DWORD numChars) { DWORD num; num = GetProfileStringW(L"intl",type,L"",string,numChars); #ifdef CL_DEBUG if (num > 0) { printf("%ws string from ini file = %ws\n",type, string); } else { printf("%ws string from ini file = (empty)\n",type); } #endif return(num); }