ReactOS 0.4.16-dev-106-g10b08aa
thmserver.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: base/services/thmsvc/thmserver.c
5 * PURPOSE: Themes server
6 * PROGRAMMER: Giannis Adamopoulos
7 */
8
9/*
10 * NOTE:
11 * ThemeWaitForServiceReady and ThemeWatchForStart are called from msgina
12 * so all the functions in this file run in the context of winlogon
13 */
14
15/* INCLUDES *****************************************************************/
16
17#include <windows.h>
18#include <uxtheme.h>
19#include <uxundoc.h>
20#include <wine/debug.h>
21
23
24/* GLOBALS ******************************************************************/
25
26static WCHAR ServiceName[] = L"Themes";
27
30
32
33/* FUNCTIONS *****************************************************************/
34
35static
38{
39 SC_HANDLE scm, service;
42 HANDLE ret;
43
44 if (!(scm = OpenSCManagerW( NULL, NULL, 0 )))
45 {
46 ERR( "failed to open service manager\n" );
47 return NULL;
48 }
49 if (!(service = OpenServiceW( scm, ServiceName, SERVICE_QUERY_STATUS )))
50 {
51 ERR( "failed to open themes service\n" );
52 CloseServiceHandle( scm );
53 return NULL;
54 }
55
57 (BYTE *)&status, sizeof(status), &dummy ))
58 {
59 ERR("QueryServiceStatusEx failed\n");
60 CloseServiceHandle( service );
61 CloseServiceHandle( scm );
62 return NULL;
63 }
64
65 ret = OpenProcess(SYNCHRONIZE, FALSE, status.dwProcessId);
66
67 CloseServiceHandle( service );
68 CloseServiceHandle( scm );
69
70 return ret;
71}
72
73static
74VOID
76ThemeStopCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
77{
80
83}
84
85static
86VOID
88ThemeServiceDiedCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
89{
90 /* The theme service died and we don't know if it could set its events properly */
93
98}
99
100static
101VOID
103ThemeStartCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
104{
106
109
111}
112
113BOOL
114WINAPI
116{
117 hStartEvent = CreateEventW(NULL, TRUE, FALSE, L"Global\\ThemeStartEvent");
118 hStopEvent = CreateEventW(NULL, TRUE, FALSE, L"Global\\ThemeStopEvent");
119
121
122 return TRUE;
123}
124
125DWORD
126WINAPI
128{
129 SC_HANDLE scm, service;
131 BOOL ret = FALSE;
132 DWORD start_time = GetTickCount();
133
134 TRACE("\n");
135
136 if (!(scm = OpenSCManagerW( NULL, NULL, 0 )))
137 {
138 ERR( "failed to open service manager\n" );
139 return FALSE;
140 }
141 if (!(service = OpenServiceW( scm, ServiceName, SERVICE_QUERY_STATUS )))
142 {
143 ERR( "failed to open themes service\n" );
144 CloseServiceHandle( scm );
145 return FALSE;
146 }
147
148 while(TRUE)
149 {
150 DWORD dummy;
151
153 (BYTE *)&status, sizeof(status), &dummy ))
154 break;
155 if (status.dwCurrentState == SERVICE_RUNNING)
156 {
157 ret = TRUE;
158 break;
159 }
160 if (status.dwCurrentState != SERVICE_START_PENDING)
161 {
162 break;
163 }
164
165 if (GetTickCount() - start_time > dwTimeout)
166 {
167 break;
168 }
169 Sleep( 100 );
170 };
171
172 CloseServiceHandle( service );
173 CloseServiceHandle( scm );
174 return ret;
175}
176
177/* EOF */
unsigned char BOOLEAN
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define CALLBACK
Definition: compat.h:35
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SYNCHRONIZE
Definition: nt_native.h:61
#define L(x)
Definition: ntvdm.h:50
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2887
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
#define TRACE(s)
Definition: solgame.cpp:4
Definition: ps.c:97
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
BOOL WINAPI RegisterWaitForSingleObject(OUT PHANDLE phNewWaitObject, IN HANDLE hObject, IN WAITORTIMERCALLBACK Callback, IN PVOID Context, IN ULONG dwMilliseconds, IN ULONG dwFlags)
Definition: synch.c:850
BOOL WINAPI UnregisterWait(IN HANDLE WaitHandle)
Definition: synch.c:934
BOOL WINAPI ThemeHooksRemove()
Definition: themehooks.c:735
BOOL WINAPI ThemeHooksInstall()
Definition: themehooks.c:693
static WCHAR ServiceName[]
Definition: thmserver.c:26
static VOID CALLBACK ThemeServiceDiedCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
Definition: thmserver.c:88
static HANDLE GetThemeServiceProcessHandle(VOID)
Definition: thmserver.c:37
HANDLE hStartEvent
Definition: thmserver.c:29
static VOID CALLBACK ThemeStartCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
Definition: thmserver.c:103
HANDLE hServiceProcess
Definition: thmserver.c:29
DWORD WINAPI ThemeWaitForServiceReady(DWORD dwTimeout)
Definition: thmserver.c:127
HANDLE hThemeStartWaitObject
Definition: thmserver.c:28
HANDLE hThemeServiceWaitObject
Definition: thmserver.c:28
HANDLE hStopEvent
Definition: thmserver.c:29
static VOID CALLBACK ThemeStopCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
Definition: thmserver.c:76
BOOL WINAPI ThemeWatchForStart(VOID)
Definition: thmserver.c:115
HANDLE hThemeStopWaitObject
Definition: thmserver.c:28
int ret
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD dwTimeout
Definition: wincrypt.h:6081
#define WINAPI
Definition: msvc.h:6
#define WT_EXECUTEONLYONCE
Definition: winnt_old.h:1042
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
@ SC_STATUS_PROCESS_INFO
Definition: winsvc.h:119
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193