/* INCLUDES ******************************************************************/
#include "svchost.h"
+
+#define NDEBUG
#include <debug.h>
#ifdef _MSC_VER
HeapFree(GetProcessHeap(), 0, Buffer);
/* Load the service dll */
+ DPRINT1("Trying to load dll\n");
hServiceDll = LoadLibrary(DllPath);
if (NULL == hServiceDll)
{
- DPRINT1("Unable to load ServiceDll: %s\n", DllPath);
+ DPRINT1("Unable to load ServiceDll: %s, ErrorCode: %u\n", DllPath, GetLastError());
return FALSE;
}
return TRUE;
}
-VOID FreeServices()
+VOID FreeServices(VOID)
{
while (FirstService)
{
{
DWORD NrOfServices;
LPSERVICE_TABLE_ENTRY ServiceTable;
- DWORD i;
if (argc < 3)
{
/* MS svchost.exe doesn't seem to print help, should we? */
- return 1;
+ return 0;
}
if (_tcscmp(argv[1], _T("-k")) != 0)
{
/* For now, we only handle "-k" */
- return 1;
+ return 0;
}
NrOfServices = LoadServiceCategory(argv[2]);
+ DPRINT1("NrOfServices: %lu\n", NrOfServices);
if (0 == NrOfServices)
- return 1;
+ return 0;
ServiceTable = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_TABLE_ENTRY) * (NrOfServices + 1));
if (NULL != ServiceTable)
{
+ DWORD i;
PSERVICE Service = FirstService;
+ /* Fill the service table */
for (i = 0; i < NrOfServices; ++i)
{
+ DPRINT1("Loading service: %s\n", Service->Name);
ServiceTable[i].lpServiceName = Service->Name;
ServiceTable[i].lpServiceProc = Service->ServiceMainFunc;
Service = Service->Next;
}
- StartServiceCtrlDispatcher(ServiceTable);
+ /* Set a NULL entry to end the service table */
+ ServiceTable[i].lpServiceName = NULL;
+ ServiceTable[i].lpServiceProc = NULL;
+
+ if (FALSE == StartServiceCtrlDispatcher(ServiceTable))
+ printf("Failed to start service control dispatcher, ErrorCode: %lu\n", GetLastError());
HeapFree(GetProcessHeap(), 0, ServiceTable);
}
DPRINT1("Not enough memory for the service table, trying to allocate %u bytes\n", sizeof(SERVICE_TABLE_ENTRY) * (NrOfServices + 1));
}
+ DPRINT1("Freeing services...\n");
FreeServices();
return 0;