ReactOS 0.4.16-dev-197-g92996da
dependencies_tv1.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/dependencies_tv1.c
5 * PURPOSE: Helper functions for service dependents
6 * COPYRIGHT: Copyright 2009 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10#include "precomp.h"
11
13TV1_GetDependants(SC_HANDLE hService)
14{
15 LPQUERY_SERVICE_CONFIG lpServiceConfig;
16 LPWSTR lpStr = NULL;
17 DWORD bytesNeeded;
19
20 /* Get the info for this service */
21 if (!QueryServiceConfigW(hService,
22 NULL,
23 0,
24 &bytesNeeded) &&
26 {
27 lpServiceConfig = HeapAlloc(ProcessHeap,
28 0,
29 bytesNeeded);
30 if (lpServiceConfig)
31 {
32 if (QueryServiceConfigW(hService,
33 lpServiceConfig,
34 bytesNeeded,
35 &bytesNeeded))
36 {
37 /* Does this service have any dependencies? */
38 if (lpServiceConfig->lpDependencies &&
39 *lpServiceConfig->lpDependencies != '\0')
40 {
41 lpStr = lpServiceConfig->lpDependencies;
42 bytes = 0;
43
44 /* Work out how many bytes we need to hold the list */
45 for (;;)
46 {
47 bytes++;
48
49 if (!*lpStr && !*(lpStr + 1))
50 {
51 bytes++;
52 break;
53 }
54
55 lpStr++;
56 }
57
58 /* Allocate and copy the list */
59 bytes *= sizeof(WCHAR);
60 lpStr = HeapAlloc(ProcessHeap,
61 0,
62 bytes);
63 if (lpStr)
64 {
65 CopyMemory(lpStr,
66 lpServiceConfig->lpDependencies,
67 bytes);
68 }
69 }
70 }
71
73 0,
74 lpServiceConfig);
75 }
76 }
77
78 return lpStr;
79}
80
81VOID
83 HTREEITEM hParent,
84 LPWSTR lpServiceName)
85{
86 SC_HANDLE hSCManager;
87 SC_HANDLE hService;
88 LPQUERY_SERVICE_CONFIG lpServiceConfig;
89 LPWSTR lpDependants;
90 LPWSTR lpStr;
91 LPWSTR lpNoDepends;
92 BOOL bHasChildren;
93
95 NULL,
97 if (hSCManager)
98 {
99 hService = OpenServiceW(hSCManager,
100 lpServiceName,
102 if (hService)
103 {
104 /* Get a list of service dependents */
105 lpDependants = TV1_GetDependants(hService);
106 if (lpDependants)
107 {
108 lpStr = lpDependants;
109
110 /* Make sure this isn't the end of the list */
111 while (*lpStr)
112 {
113 /* Get the info for this service */
114 lpServiceConfig = GetServiceConfig(lpStr);
115 if (lpServiceConfig)
116 {
117 /* Does this item need a +/- box? */
118 if (lpServiceConfig->lpDependencies &&
119 *lpServiceConfig->lpDependencies != '\0')
120 {
121 bHasChildren = TRUE;
122 }
123 else
124 {
125 bHasChildren = FALSE;
126 }
127
128 /* Add it */
130 hParent,
131 lpServiceConfig->lpDisplayName,
132 lpStr,
133 lpServiceConfig->dwServiceType,
134 bHasChildren);
135
137 0,
138 lpServiceConfig);
139 }
140
141 /* Move to the end of the string */
142 while (*lpStr++)
143 ;
144 }
145
147 0,
148 lpDependants);
149 }
150 else
151 {
152 /* If there is no parent, set the tree to 'no dependencies' */
153 if (!hParent)
154 {
155 /* Load the 'No dependencies' string */
157
159 NULL,
160 lpNoDepends,
161 NULL,
162 0,
163 FALSE);
164
165 LocalFree(lpNoDepends);
166
167 /* Disable the window */
168 EnableWindow(pDependData->hDependsTreeView1, FALSE);
169 }
170 }
171
172 CloseServiceHandle(hService);
173 }
174
176 }
177}
178
179BOOL
181 LPWSTR lpServiceName)
182{
183 BOOL bRet = FALSE;
184
185 /* Associate the imagelist with TV1 */
186 pDependData->hDependsTreeView1 = GetDlgItem(pDependData->hDependsWnd, IDC_DEPEND_TREE1);
187 if (!pDependData->hDependsTreeView1)
188 {
190 pDependData->hDependsImageList = NULL;
191 return FALSE;
192 }
194 pDependData->hDependsImageList,
196
197 /* Set the first items in the control */
198 TV1_AddDependantsToTree(pDependData, NULL, lpServiceName);
199
200 return bRet;
201}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
LPQUERY_SERVICE_CONFIG GetServiceConfig(LPWSTR lpServiceName)
Definition: query.c:29
HTREEITEM AddItemToTreeView(HWND hTreeView, HTREEITEM hRoot, LPWSTR lpDisplayName, LPWSTR lpServiceName, ULONG serviceType, BOOL bHasChildren)
HANDLE ProcessHeap
Definition: servman.c:15
#define IDC_DEPEND_TREE1
Definition: resource.h:175
#define IDS_NO_DEPENDS
Definition: resource.h:178
HINSTANCE hInstance
Definition: charmap.c:19
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
BOOL TV1_Initialize(PDEPENDDATA pDependData, LPWSTR lpServiceName)
VOID TV1_AddDependantsToTree(PDEPENDDATA pDependData, HTREEITEM hParent, LPWSTR lpServiceName)
LPWSTR TV1_GetDependants(SC_HANDLE hService)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define TVSIL_NORMAL
Definition: commctrl.h:3448
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3452
SC_HANDLE hSCManager
Definition: sc.c:12
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI QueryServiceConfigW(SC_HANDLE hService, LPQUERY_SERVICE_CONFIGW lpServiceConfig, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2291
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
HWND hDependsTreeView1
Definition: precomp.h:141
HIMAGELIST hDependsImageList
Definition: precomp.h:139
HWND hDependsWnd
Definition: precomp.h:140
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1734
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
#define SERVICE_ENUMERATE_DEPENDENTS
Definition: winsvc.h:56
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184