- success = UpdateSCMStatus(SERVICE_START_PENDING, NO_ERROR, 0, 2, 1000);
- if (!success)
- {
- terminateService(EXIT_STATUS_UPDATESCM_FAILED, GetLastError());
- return;
+ uint32_t allocsize = strnlen_s(szModuleName, MAX_PATH) + 1;
+ g_ServiceData.argv[0] = new char[allocsize];
+ strcpy_s(g_ServiceData.argv[0], allocsize, szModuleName);
+
+ for(uint32_t i = 1; i < argc; i++)
+ {
+ allocsize = strnlen_s(argv[i], MAX_PATH) + 1;
+ g_ServiceData.argv[i] = new char[allocsize];
+ strcpy_s(g_ServiceData.argv[i], allocsize, argv[i]);
+ }
+
+ *(strrchr(szModuleName, '\\') + 1) = NULL;
+ SetCurrentDirectoryA(szModuleName);
+
+ HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WorkerThread, NULL, 0, NULL);
+ if (hThread != NULL)
+ {
+ WaitForSingleObject(hThread, INFINITE);
+ CloseHandle(hThread);
+ }
+ }
+ catch(...)
+ {
+ g_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ g_ServiceStatus.dwWin32ExitCode = ERROR_OUTOFMEMORY;
+ SetServiceStatus( g_ServiceStatusHandle, &g_ServiceStatus );
+ }