| 16 | } |
| 17 | |
| 18 | VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv) |
| 19 | { |
| 20 | |
| 21 | DWORD Status = E_FAIL; |
| 22 | HANDLE hThread = INVALID_HANDLE_VALUE; |
| 23 | if (argc == 1 || argc == 0) |
| 24 | { |
| 25 | OutputDebugString("AmdK9: No argument"); |
| 26 | return; |
| 27 | } |
| 28 | g_StatusHandle = RegisterServiceCtrlHandler(SERVICE_NAME, ServiceHandler); |
| 29 | |
| 30 | if (g_StatusHandle == NULL) |
| 31 | { |
| 32 | OutputDebugString("AmdK9: RegisterServiceCtrlHandler failed"); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | ZeroMemory(&g_ServiceStatus, sizeof(g_ServiceStatus)); |
| 37 | g_ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; |
| 38 | g_ServiceStatus.dwControlsAccepted = 0; |
| 39 | g_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; |
| 40 | g_ServiceStatus.dwWin32ExitCode = 0; |
| 41 | g_ServiceStatus.dwServiceSpecificExitCode = 0; |
| 42 | g_ServiceStatus.dwCheckPoint = 0; |
| 43 | if (SetServiceStatus(g_StatusHandle, &g_ServiceStatus) == FALSE) |
| 44 | OutputDebugString(("AmdK9: SetServiceStatus returned error")); |
| 45 | |
| 46 | g_ServiceStopEvent = CreateEventA(NULL, TRUE, FALSE, NULL); |
| 47 | if (g_ServiceStopEvent == NULL) |
| 48 | { |
| 49 | g_ServiceStatus.dwControlsAccepted = 0; |
| 50 | g_ServiceStatus.dwCurrentState = SERVICE_STOPPED; |
| 51 | g_ServiceStatus.dwWin32ExitCode = GetLastError(); |
| 52 | g_ServiceStatus.dwCheckPoint = 1; |
| 53 | |
| 54 | if (SetServiceStatus(g_StatusHandle, &g_ServiceStatus) == FALSE) |
| 55 | { |
| 56 | OutputDebugString("AmdK9: SetServiceStatus returned error"); |
| 57 | } |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | g_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; |
| 62 | g_ServiceStatus.dwCurrentState = SERVICE_RUNNING; |
| 63 | g_ServiceStatus.dwWin32ExitCode = 0; |
| 64 | g_ServiceStatus.dwCheckPoint = 0; |
| 65 | |
| 66 | if (SetServiceStatus(g_StatusHandle, &g_ServiceStatus) == FALSE) |
| 67 | OutputDebugString("AmdK9: SetServiceStatus returned error"); |
| 68 | |
| 69 | hThread = CreateThread(NULL, 0, ServiceThread, argv[argc - 1], 0, NULL); |
| 70 | Threads.push_back(hThread); |
| 71 | WaitForSingleObject(hThread, INFINITE); |
| 72 | CloseHandle(g_ServiceStopEvent); |
| 73 | |
| 74 | g_ServiceStatus.dwControlsAccepted = 0; |
| 75 | g_ServiceStatus.dwCurrentState = SERVICE_STOPPED; |
nothing calls this directly
no outgoing calls
no test coverage detected