mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 17:05:45 +00:00
[SVCHOST]
- Make WCHARs explicit svn path=/trunk/; revision=59359
This commit is contained in:
parent
75877f2763
commit
31e65c22bf
2 changed files with 26 additions and 27 deletions
|
@ -15,38 +15,38 @@
|
||||||
|
|
||||||
/* DEFINES *******************************************************************/
|
/* DEFINES *******************************************************************/
|
||||||
|
|
||||||
static LPCTSTR SVCHOST_REG_KEY = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SvcHost");
|
static PCWSTR SVCHOST_REG_KEY = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SvcHost";
|
||||||
static LPCTSTR SERVICE_KEY = _T("SYSTEM\\CurrentControlSet\\Services\\");
|
static PCWSTR SERVICE_KEY = L"SYSTEM\\CurrentControlSet\\Services\\";
|
||||||
static LPCTSTR PARAMETERS_KEY = _T("\\Parameters");
|
static PCWSTR PARAMETERS_KEY = L"\\Parameters";
|
||||||
|
|
||||||
#define SERVICE_KEY_LENGTH _tcslen(SERVICE_KEY);
|
#define SERVICE_KEY_LENGTH wcslen(SERVICE_KEY);
|
||||||
#define REG_MAX_DATA_SIZE 2048
|
#define REG_MAX_DATA_SIZE 2048
|
||||||
|
|
||||||
static PSERVICE FirstService = NULL;
|
static PSERVICE FirstService = NULL;
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
BOOL PrepareService(LPCTSTR ServiceName)
|
BOOL PrepareService(PCWSTR ServiceName)
|
||||||
{
|
{
|
||||||
HKEY hServiceKey;
|
HKEY hServiceKey;
|
||||||
TCHAR ServiceKeyBuffer[MAX_PATH + 1];
|
WCHAR ServiceKeyBuffer[MAX_PATH + 1];
|
||||||
DWORD LeftOfBuffer = sizeof(ServiceKeyBuffer) / sizeof(ServiceKeyBuffer[0]);
|
DWORD LeftOfBuffer = sizeof(ServiceKeyBuffer) / sizeof(ServiceKeyBuffer[0]);
|
||||||
DWORD KeyType;
|
DWORD KeyType;
|
||||||
PTSTR Buffer = NULL;
|
PWSTR Buffer = NULL;
|
||||||
DWORD BufferSize = MAX_PATH + 1;
|
DWORD BufferSize = MAX_PATH + 1;
|
||||||
LONG RetVal;
|
LONG RetVal;
|
||||||
HINSTANCE hServiceDll;
|
HINSTANCE hServiceDll;
|
||||||
TCHAR DllPath[MAX_PATH + 2]; /* See MSDN on ExpandEnvironmentStrings() for ANSI strings for more details on + 2 */
|
WCHAR DllPath[MAX_PATH + 2]; /* See MSDN on ExpandEnvironmentStrings() for ANSI strings for more details on + 2 */
|
||||||
LPSERVICE_MAIN_FUNCTION ServiceMainFunc;
|
LPSERVICE_MAIN_FUNCTION ServiceMainFunc;
|
||||||
PSERVICE Service;
|
PSERVICE Service;
|
||||||
|
|
||||||
/* Compose the registry path to the service's "Parameter" key */
|
/* Compose the registry path to the service's "Parameter" key */
|
||||||
_tcsncpy(ServiceKeyBuffer, SERVICE_KEY, LeftOfBuffer);
|
wcsncpy(ServiceKeyBuffer, SERVICE_KEY, LeftOfBuffer);
|
||||||
LeftOfBuffer -= _tcslen(SERVICE_KEY);
|
LeftOfBuffer -= wcslen(SERVICE_KEY);
|
||||||
_tcsncat(ServiceKeyBuffer, ServiceName, LeftOfBuffer);
|
wcsncat(ServiceKeyBuffer, ServiceName, LeftOfBuffer);
|
||||||
LeftOfBuffer -= _tcslen(ServiceName);
|
LeftOfBuffer -= wcslen(ServiceName);
|
||||||
_tcsncat(ServiceKeyBuffer, PARAMETERS_KEY, LeftOfBuffer);
|
wcsncat(ServiceKeyBuffer, PARAMETERS_KEY, LeftOfBuffer);
|
||||||
LeftOfBuffer -= _tcslen(PARAMETERS_KEY);
|
LeftOfBuffer -= wcslen(PARAMETERS_KEY);
|
||||||
|
|
||||||
if (LeftOfBuffer < 0)
|
if (LeftOfBuffer < 0)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,7 @@ BOOL PrepareService(LPCTSTR ServiceName)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RetVal = RegQueryValueEx(hServiceKey, _T("ServiceDll"), NULL, &KeyType, (LPBYTE)Buffer, &BufferSize);
|
RetVal = RegQueryValueEx(hServiceKey, L"ServiceDll", NULL, &KeyType, (LPBYTE)Buffer, &BufferSize);
|
||||||
|
|
||||||
} while (RetVal == ERROR_MORE_DATA);
|
} while (RetVal == ERROR_MORE_DATA);
|
||||||
|
|
||||||
|
@ -119,14 +119,14 @@ BOOL PrepareService(LPCTSTR ServiceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(Service, 0, sizeof(SERVICE));
|
memset(Service, 0, sizeof(SERVICE));
|
||||||
Service->Name = HeapAlloc(GetProcessHeap(), 0, (_tcslen(ServiceName)+1) * sizeof(TCHAR));
|
Service->Name = HeapAlloc(GetProcessHeap(), 0, (wcslen(ServiceName)+1) * sizeof(WCHAR));
|
||||||
if (Service->Name == NULL)
|
if (Service->Name == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("Not enough memory for service: %s\n", ServiceName);
|
DPRINT1("Not enough memory for service: %s\n", ServiceName);
|
||||||
HeapFree(GetProcessHeap(), 0, Service);
|
HeapFree(GetProcessHeap(), 0, Service);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
_tcscpy(Service->Name, ServiceName);
|
wcscpy(Service->Name, ServiceName);
|
||||||
|
|
||||||
Service->hServiceDll = hServiceDll;
|
Service->hServiceDll = hServiceDll;
|
||||||
Service->ServiceMainFunc = ServiceMainFunc;
|
Service->ServiceMainFunc = ServiceMainFunc;
|
||||||
|
@ -154,13 +154,13 @@ VOID FreeServices(VOID)
|
||||||
/*
|
/*
|
||||||
* Returns the number of services successfully loaded from the category
|
* Returns the number of services successfully loaded from the category
|
||||||
*/
|
*/
|
||||||
DWORD LoadServiceCategory(LPCTSTR ServiceCategory)
|
DWORD LoadServiceCategory(PCWSTR ServiceCategory)
|
||||||
{
|
{
|
||||||
HKEY hServicesKey;
|
HKEY hServicesKey;
|
||||||
DWORD KeyType;
|
DWORD KeyType;
|
||||||
DWORD BufferSize = REG_MAX_DATA_SIZE;
|
DWORD BufferSize = REG_MAX_DATA_SIZE;
|
||||||
TCHAR Buffer[REG_MAX_DATA_SIZE];
|
WCHAR Buffer[REG_MAX_DATA_SIZE];
|
||||||
LPCTSTR ServiceName;
|
PCWSTR ServiceName;
|
||||||
DWORD BufferIndex = 0;
|
DWORD BufferIndex = 0;
|
||||||
DWORD NrOfServices = 0;
|
DWORD NrOfServices = 0;
|
||||||
|
|
||||||
|
@ -183,11 +183,11 @@ DWORD LoadServiceCategory(LPCTSTR ServiceCategory)
|
||||||
|
|
||||||
/* Load services in the category */
|
/* Load services in the category */
|
||||||
ServiceName = Buffer;
|
ServiceName = Buffer;
|
||||||
while (ServiceName[0] != _T('\0'))
|
while (ServiceName[0] != UNICODE_NULL)
|
||||||
{
|
{
|
||||||
size_t Length;
|
size_t Length;
|
||||||
|
|
||||||
Length = _tcslen(ServiceName);
|
Length = wcslen(ServiceName);
|
||||||
if (Length == 0)
|
if (Length == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ DWORD LoadServiceCategory(LPCTSTR ServiceCategory)
|
||||||
return NrOfServices;
|
return NrOfServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _tmain (int argc, LPTSTR argv [])
|
int wmain(int argc, wchar_t **argv)
|
||||||
{
|
{
|
||||||
DWORD NrOfServices;
|
DWORD NrOfServices;
|
||||||
LPSERVICE_TABLE_ENTRY ServiceTable;
|
LPSERVICE_TABLE_ENTRY ServiceTable;
|
||||||
|
@ -213,7 +213,7 @@ int _tmain (int argc, LPTSTR argv [])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tcscmp(argv[1], _T("-k")) != 0)
|
if (wcscmp(argv[1], L"-k") != 0)
|
||||||
{
|
{
|
||||||
/* For now, we only handle "-k" */
|
/* For now, we only handle "-k" */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -20,14 +20,13 @@
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <winreg.h>
|
#include <winreg.h>
|
||||||
#include <winsvc.h>
|
#include <winsvc.h>
|
||||||
#include <tchar.h>
|
|
||||||
|
|
||||||
/* DEFINES *******************************************************************/
|
/* DEFINES *******************************************************************/
|
||||||
|
|
||||||
#define CS_TIMEOUT 1000
|
#define CS_TIMEOUT 1000
|
||||||
|
|
||||||
typedef struct _SERVICE {
|
typedef struct _SERVICE {
|
||||||
PTSTR Name;
|
PWSTR Name;
|
||||||
HINSTANCE hServiceDll;
|
HINSTANCE hServiceDll;
|
||||||
LPSERVICE_MAIN_FUNCTION ServiceMainFunc;
|
LPSERVICE_MAIN_FUNCTION ServiceMainFunc;
|
||||||
struct _SERVICE *Next;
|
struct _SERVICE *Next;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue