main.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2007 Jacek Caban for CodeWeavers
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. */
  18. #define WIN32_LEAN_AND_MEAN
  19. #include <windows.h>
  20. #include <winsvc.h>
  21. #include "wine/debug.h"
  22. WINE_DEFAULT_DEBUG_CHANNEL(spoolsv);
  23. static WCHAR spoolerW[] = L"Spooler";
  24. static SERVICE_STATUS_HANDLE service_handle;
  25. static HANDLE stop_event;
  26. static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
  27. {
  28. SERVICE_STATUS status;
  29. status.dwServiceType = SERVICE_WIN32;
  30. status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
  31. status.dwWin32ExitCode = 0;
  32. status.dwServiceSpecificExitCode = 0;
  33. status.dwCheckPoint = 0;
  34. status.dwWaitHint = 0;
  35. switch(ctrl)
  36. {
  37. case SERVICE_CONTROL_STOP:
  38. case SERVICE_CONTROL_SHUTDOWN:
  39. WINE_TRACE( "shutting down\n" );
  40. status.dwCurrentState = SERVICE_STOP_PENDING;
  41. status.dwControlsAccepted = 0;
  42. SetServiceStatus( service_handle, &status );
  43. SetEvent( stop_event );
  44. return NO_ERROR;
  45. default:
  46. WINE_FIXME( "got service ctrl %x\n", ctrl );
  47. status.dwCurrentState = SERVICE_RUNNING;
  48. SetServiceStatus( service_handle, &status );
  49. return NO_ERROR;
  50. }
  51. }
  52. static void WINAPI serv_main(DWORD argc, LPWSTR *argv)
  53. {
  54. SERVICE_STATUS status;
  55. WINE_TRACE( "starting service\n" );
  56. stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
  57. service_handle = RegisterServiceCtrlHandlerExW( spoolerW, service_handler, NULL );
  58. if (!service_handle)
  59. return;
  60. status.dwServiceType = SERVICE_WIN32;
  61. status.dwCurrentState = SERVICE_RUNNING;
  62. status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
  63. status.dwWin32ExitCode = 0;
  64. status.dwServiceSpecificExitCode = 0;
  65. status.dwCheckPoint = 0;
  66. status.dwWaitHint = 10000;
  67. SetServiceStatus( service_handle, &status );
  68. WaitForSingleObject( stop_event, INFINITE );
  69. status.dwCurrentState = SERVICE_STOPPED;
  70. status.dwControlsAccepted = 0;
  71. SetServiceStatus( service_handle, &status );
  72. WINE_TRACE( "service stopped\n" );
  73. }
  74. int __cdecl main(int argc, char **argv)
  75. {
  76. static const SERVICE_TABLE_ENTRYW servtbl[] = {
  77. {spoolerW, serv_main},
  78. {NULL, NULL}
  79. };
  80. WINE_TRACE("(%d %p)\n", argc, argv);
  81. StartServiceCtrlDispatcherW(servtbl);
  82. return 0;
  83. }