2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/dependencies.c
5 * PURPOSE: Helper functions for service dependents
6 * COPYRIGHT: Copyright 2006-2009 Ged Murphy <gedmurphy@reactos.org>
14 * Services which depend on the given service.
15 * The return components depend on this service
18 GetDependentServices(SC_HANDLE hService
)
20 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
25 if (!QueryServiceConfig(hService
,
29 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
31 lpServiceConfig
= HeapAlloc(ProcessHeap
,
36 if (QueryServiceConfig(hService
,
43 lpStr
= lpServiceConfig
->lpDependencies
;
50 if (!*lpStr
&& !*(lpStr
+ 1))
59 bytes
*= sizeof(TCHAR
);
60 lpStr
= HeapAlloc(ProcessHeap
,
66 lpServiceConfig
->lpDependencies
,
79 * Services which the given service depends on (1st treeview)
80 * The service depends on the return components
83 GetServiceDependents(SC_HANDLE hService
,
86 LPENUM_SERVICE_STATUS lpDependencies
;
90 if (EnumDependentServices(hService
,
97 /* There are no dependent services */
102 if (GetLastError() != ERROR_MORE_DATA
)
103 return NULL
; /* Unexpected error */
105 lpDependencies
= (LPENUM_SERVICE_STATUS
)HeapAlloc(GetProcessHeap(),
110 if (EnumDependentServices(hService
,
117 *lpdwCount
= dwCount
;
121 HeapFree(ProcessHeap
,
125 lpDependencies
= NULL
;
130 return lpDependencies
;
136 HasDependentServices(SC_HANDLE hService
)
138 DWORD dwBytesNeeded
, dwCount
;
143 if (!EnumDependentServices(hService
,
150 if (GetLastError() == ERROR_MORE_DATA
)
159 DoInitDependsDialog(PSTOP_INFO pStopInfo
,
162 LPENUM_SERVICE_STATUS lpDependencies
;
164 LPTSTR lpPartialStr
, lpStr
;
171 SetWindowLongPtr(hDlg
,
173 (LONG_PTR
)pStopInfo
);
175 hIcon
= (HICON
)LoadImage(hInstance
,
176 MAKEINTRESOURCE(IDI_SM_ICON
),
191 if (AllocAndLoadString(&lpPartialStr
,
195 fullLen
= _tcslen(lpPartialStr
) + _tcslen(pStopInfo
->pInfo
->pCurrentService
->lpDisplayName
) + 1;
197 lpStr
= HeapAlloc(ProcessHeap
,
199 fullLen
* sizeof(TCHAR
));
202 _sntprintf(lpStr
, fullLen
, lpPartialStr
, pStopInfo
->pInfo
->pCurrentService
->lpDisplayName
);
204 SendDlgItemMessage(hDlg
,
212 HeapFree(ProcessHeap
,
217 HeapFree(ProcessHeap
,
222 /* Get the list of dependencies */
223 lpDependencies
= GetServiceDependents(pStopInfo
->hMainService
, &dwCount
);
226 LPENUM_SERVICE_STATUS lpEnumServiceStatus
;
229 for (i
= 0; i
< dwCount
; i
++)
231 lpEnumServiceStatus
= &lpDependencies
[i
];
233 /* Add the service to the listbox */
234 SendDlgItemMessage(hDlg
,
238 (LPARAM
)lpEnumServiceStatus
->lpDisplayName
);
241 HeapFree(ProcessHeap
,
252 StopDependsDialogProc(HWND hDlg
,
257 PSTOP_INFO pStopInfo
= NULL
;
259 /* Get the window context */
260 pStopInfo
= (PSTOP_INFO
)GetWindowLongPtr(hDlg
,
262 if (pStopInfo
== NULL
&& message
!= WM_INITDIALOG
)
273 pStopInfo
= (PSTOP_INFO
)lParam
;
274 if (pStopInfo
!= NULL
)
276 bRet
= DoInitDependsDialog(pStopInfo
, hDlg
);
284 switch (LOWORD(wParam
))