Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void StartwinService();
- int wmain(int argc, wchar_t *argv[])
- {
- if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/'))))
- {
- if (_wcsicmp(L"install", argv[1] + 1) == 0)
- {
- // Install the service when the command is
- // "-install" or "/install".
- InstallService(
- SERVICE_NAME, // Name of service
- SERVICE_DISPLAY_NAME, // Name to display
- SERVICE_START_TYPE, // Service start type
- SERVICE_DEPENDENCIES, // Dependencies
- SERVICE_ACCOUNT, // Service running account
- SERVICE_PASSWORD // Password of the account
- );
- DWORD mainthreadID = ::GetCurrentThreadId();
- // Inits the server named pipes and starts waiting for connection in another thread.
- ServerPipe SP;
- SP.Init(mainthreadID);
- MSG msg;
- static bool bDone = false;
- while (GetMessage(&msg,NULL,0,0) && !bDone) {
- if(msg.message==WM_COMMAND)
- switch((UINT)msg.wParam)
- {
- // server pipes post this message to main thread, when received a request from the Notify tray icon.
- case WM_START_SERVICE:
- LOG(LS_INFO)<<"WM_START_SERVICE";
- StartwinService();
- bDone = true; // quits the main loop
- break;
- case WM_STOP_SERVICE:
- LOG(LS_INFO)<<"WM_STOP_SERVICE";
- bDone = true;
- break;
- default:
- LOG(LS_INFO)<<"UNKNOWN Message:"<<(UINT)msg.wParam;
- break;
- } // end of switch condition.
- } // end of while loop.
- }
- else if (_wcsicmp(L"remove", argv[1] + 1) == 0)
- {
- // Uninstall the service when the command is
- // "-remove" or "/remove".
- UninstallService(SERVICE_NAME);
- }
- }
- return 0;
- }
- void StartwinService(){
- ////////////// THIS IS FAILING WITH 1063 ERROR /////////////////////
- CSampleService service(SERVICE_NAME);
- if (!CServiceBase::Run(service))
- wprintf(L"Service failed to run w/err 0x%08lx\n",
- GetLastError());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement