ReactOS  0.4.14-dev-552-g2fad488
dcomlaunch.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS RPC Subsystem Service
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: DCOMLAUNCH service
5  * COPYRIGHT: Copyright 2019 Pierre Schweitzer
6  */
7 
8 /* INCLUDES *****************************************************************/
9 
10 #define WIN32_NO_STATUS
11 #define _INC_WINDOWS
12 #define COM_NO_WINDOWS_H
13 #include <stdarg.h>
14 #include <windef.h>
15 #include <winbase.h>
16 #include <winreg.h>
17 #include <winsvc.h>
18 
19 #define NDEBUG
20 #include <debug.h>
21 
22 /* GLOBALS ******************************************************************/
23 
24 static WCHAR ServiceName[] = L"dcomlaunch";
25 
29 
30 /* FUNCTIONS *****************************************************************/
31 
32 static VOID
34 {
36  ServiceStatus.dwCurrentState = dwState;
41 
42  if (dwState == SERVICE_START_PENDING ||
43  dwState == SERVICE_STOP_PENDING ||
44  dwState == SERVICE_PAUSE_PENDING ||
45  dwState == SERVICE_CONTINUE_PENDING)
46  ServiceStatus.dwWaitHint = 10000;
47  else
49 
51  &ServiceStatus);
52 }
53 
54 static DWORD WINAPI
56  DWORD dwEventType,
57  LPVOID lpEventData,
58  LPVOID lpContext)
59 {
60  DPRINT1("ServiceControlHandler() called\n");
61 
62  switch (dwControl)
63  {
65  DPRINT1(" SERVICE_CONTROL_STOP received\n");
68  return ERROR_SUCCESS;
69 
71  DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
73  return ERROR_SUCCESS;
74 
76  DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
78  return ERROR_SUCCESS;
79 
81  DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
83  &ServiceStatus);
84  return ERROR_SUCCESS;
85 
87  DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
90  return ERROR_SUCCESS;
91 
92  default :
93  DPRINT1(" Control %lu received\n");
95  }
96 }
97 
99 
100 VOID WINAPI
102 {
105 
106  DPRINT("ServiceMain() called\n");
107 
110  NULL);
111  if (!ServiceStatusHandle)
112  {
113  DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
114  return;
115  }
116 
118 
120 
122 
125 
127 }
128 
129 BOOL WINAPI
131  DWORD fdwReason,
133 {
134  switch (fdwReason)
135  {
136  case DLL_PROCESS_ATTACH:
137  DisableThreadLibraryCalls(hinstDLL);
138  break;
139 
140  case DLL_PROCESS_DETACH:
141  break;
142  }
143 
144  return TRUE;
145 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwCurrentState
Definition: winsvc.h:100
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define SERVICE_PAUSED
Definition: winsvc.h:27
static SERVICE_STATUS ServiceStatus
Definition: dcomlaunch.c:27
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dcomlaunch.c:33
#define argv
Definition: mplay32.c:18
CHAR * LPTSTR
Definition: xmlstorage.h:192
static IN DWORD IN LPVOID lpvReserved
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: dcomlaunch.c:26
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:995
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: dcomlaunch.c:55
void DPRINT(...)
Definition: polytest.cpp:61
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define DLL_PROCESS_DETACH
Definition: compat.h:119
static HANDLE ShutdownEvent
Definition: dcomlaunch.c:28
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwWaitHint
Definition: winsvc.h:105
#define WINAPI
Definition: msvc.h:8
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
static const WCHAR L[]
Definition: oid.c:1250
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:810
static WCHAR ServiceName[]
Definition: dcomlaunch.c:24
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: dcomlaunch.c:101
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
VOID DealWithDeviceEvent()
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: dcomlaunch.c:130
#define DPRINT1
Definition: precomp.h:8
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define INFINITE
Definition: serial.h:102
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40