2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/stop_dependencies.c
5 * PURPOSE: Routines related to stopping dependent services
6 * COPYRIGHT: Copyright 2006-2010 Ged Murphy <gedmurphy@reactos.org>
14 AddServiceToList(LPWSTR
*lpServiceList
,
15 LPWSTR lpServiceToAdd
)
17 LPWSTR lpNewList
= NULL
;
22 dwToAddSize
= wcslen(lpServiceToAdd
) + 1;
24 /* Is this is the first in the list? */
27 /* Add another char for double null */
30 lpNewList
= HeapAlloc(GetProcessHeap(),
32 dwToAddSize
* sizeof(WCHAR
));
35 /* Copy the service name */
40 /* Add the double null char */
41 lpNewList
[dwToAddSize
- 1] = L
'\0';
49 /* Get the list size */
52 /* Break when we hit the double null */
53 if (*ptr
== L
'\0' && *(ptr
+ 1) == L
'\0')
61 /* Add another char for double null */
64 /* Extend the list size */
65 lpNewList
= HeapReAlloc(GetProcessHeap(),
68 (dwCurSize
+ dwToAddSize
) * sizeof(WCHAR
));
71 /* Copy the service name */
72 wcscpy_s(&lpNewList
[dwCurSize
- 1],
76 /* Add the double null char */
77 lpNewList
[dwCurSize
+ dwToAddSize
- 1] = L
'\0';
85 BuildListOfServicesToStop(LPWSTR
*lpServiceList
,
88 LPENUM_SERVICE_STATUS lpServiceStatus
;
92 /* Get a list of service dependents */
93 lpServiceStatus
= TV2_GetDependants(lpServiceName
, &dwCount
);
96 for (i
= 0; i
< dwCount
; i
++)
98 /* Does this service have any dependents? */
99 if (TV2_HasDependantServices(lpServiceStatus
[i
].lpServiceName
))
101 /* recall this function with the dependent */
102 BuildListOfServicesToStop(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
105 /* Add the service to the list */
106 *lpServiceList
= AddServiceToList(lpServiceList
, lpServiceStatus
[i
].lpServiceName
);
111 HeapFree(GetProcessHeap(),
120 GetListOfServicesToStop(LPWSTR lpServiceName
)
122 LPWSTR lpServiceList
= NULL
;
124 /* Call recursive function to get our list */
125 if (BuildListOfServicesToStop(&lpServiceList
, lpServiceName
))
126 return lpServiceList
;
133 AddServiceNamesToStop(HWND hServiceListBox
,
134 LPWSTR lpServiceList
)
136 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
139 lpStr
= lpServiceList
;
141 /* Loop through all the services in the list */
144 /* Break when we hit the double null */
145 if (*lpStr
== L
'\0' && *(lpStr
+ 1) == L
'\0')
148 /* If this isn't our first time in the loop we'll
149 have been left on a null char */
153 /* Get the service's display name */
154 lpServiceConfig
= GetServiceConfig(lpStr
);
157 /* Add the service to the listbox */
158 SendMessageW(hServiceListBox
,
161 (LPARAM
)lpServiceConfig
->lpDisplayName
);
164 /* Move onto the next string */
165 while (*lpStr
!= L
'\0')
171 DoInitDependsDialog(PMAIN_WND_INFO pInfo
,
174 HWND hServiceListBox
;
175 LPWSTR lpPartialStr
, lpStr
;
182 /* Tag the info to the window */
183 SetWindowLongPtrW(hDlg
,
187 /* Load the icon for the window */
188 hIcon
= (HICON
)LoadImageW(hInstance
,
189 MAKEINTRESOURCE(IDI_SM_ICON
),
191 GetSystemMetrics(SM_CXSMICON
),
192 GetSystemMetrics(SM_CXSMICON
),
204 /* Load the stop depends note */
205 if (AllocAndLoadString(&lpPartialStr
,
209 /* Get the length required */
210 fullLen
= wcslen(lpPartialStr
) + wcslen(pInfo
->pCurrentService
->lpDisplayName
) + 1;
212 lpStr
= HeapAlloc(ProcessHeap
,
214 fullLen
* sizeof(WCHAR
));
217 /* Add the service name to the depends note */
221 pInfo
->pCurrentService
->lpDisplayName
);
223 /* Add the string to the dialog */
224 SendDlgItemMessageW(hDlg
,
230 HeapFree(ProcessHeap
,
237 HeapFree(ProcessHeap
,
242 /* Display the list of services which need stopping */
243 hServiceListBox
= GetDlgItem(hDlg
,
244 IDC_STOP_DEPENDS_LB
);
247 AddServiceNamesToStop(hServiceListBox
,
248 (LPWSTR
)pInfo
->pTag
);
257 StopDependsDialogProc(HWND hDlg
,
262 PMAIN_WND_INFO pInfo
= NULL
;
264 /* Get the window context */
265 pInfo
= (PMAIN_WND_INFO
)GetWindowLongPtrW(hDlg
,
267 if (pInfo
== NULL
&& message
!= WM_INITDIALOG
)
278 pInfo
= (PMAIN_WND_INFO
)lParam
;
281 bRet
= DoInitDependsDialog(pInfo
, hDlg
);
289 switch (LOWORD(wParam
))