Commit 6f84c8bb authored by Sergey Lyubka's avatar Sergey Lyubka

Using unicode API for service creation

parent 0adbfcba
...@@ -557,8 +557,7 @@ static HICON hIcon; ...@@ -557,8 +557,7 @@ static HICON hIcon;
static HANDLE hThread; // Serving thread static HANDLE hThread; // Serving thread
static SERVICE_STATUS ss; static SERVICE_STATUS ss;
static SERVICE_STATUS_HANDLE hStatus; static SERVICE_STATUS_HANDLE hStatus;
static const char *service_magic_argument = "--"; static const wchar_t *service_name = L"Mongoose";
static const char *service_name = "Mongoose";
static NOTIFYICONDATA TrayIcon; static NOTIFYICONDATA TrayIcon;
static void WINAPI ControlHandler(DWORD code) { static void WINAPI ControlHandler(DWORD code) {
...@@ -574,7 +573,7 @@ static void WINAPI ControlHandler(DWORD code) { ...@@ -574,7 +573,7 @@ static void WINAPI ControlHandler(DWORD code) {
} }
static void WINAPI ServiceMain(void) { static void WINAPI ServiceMain(void) {
hStatus = RegisterServiceCtrlHandler(service_name, ControlHandler); hStatus = RegisterServiceCtrlHandlerW(service_name, ControlHandler);
ControlHandler(SERVICE_CONTROL_INTERROGATE); ControlHandler(SERVICE_CONTROL_INTERROGATE);
while (ss.dwCurrentState == SERVICE_RUNNING) { while (ss.dwCurrentState == SERVICE_RUNNING) {
...@@ -863,7 +862,7 @@ static void show_settings_dialog() { ...@@ -863,7 +862,7 @@ static void show_settings_dialog() {
static int manage_service(int action) { static int manage_service(int action) {
SC_HANDLE hSCM = NULL, hService = NULL; SC_HANDLE hSCM = NULL, hService = NULL;
SERVICE_DESCRIPTION descr = {server_name}; SERVICE_DESCRIPTION descr = {server_name};
char path[PATH_MAX + 20]; // Path to executable plus magic argument wchar_t wpath[PATH_MAX + 20]; // Path to executable plus magic argument
int success = 1; int success = 1;
if ((hSCM = OpenSCManager(NULL, NULL, action == ID_INSTALL_SERVICE ? if ((hSCM = OpenSCManager(NULL, NULL, action == ID_INSTALL_SERVICE ?
...@@ -871,25 +870,24 @@ static int manage_service(int action) { ...@@ -871,25 +870,24 @@ static int manage_service(int action) {
success = 0; success = 0;
show_error(); show_error();
} else if (action == ID_INSTALL_SERVICE) { } else if (action == ID_INSTALL_SERVICE) {
GetModuleFileName(NULL, path, sizeof(path)); GetModuleFileNameW(NULL, wpath, sizeof(wpath) / sizeof(wpath[0]));
strncat(path, " ", sizeof(path)); wcsncat(wpath, L" --", sizeof(wpath) / sizeof(wpath[0]));
strncat(path, service_magic_argument, sizeof(path)); hService = CreateServiceW(hSCM, service_name, service_name,
hService = CreateService(hSCM, service_name, service_name, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, wpath, NULL, NULL, NULL, NULL, NULL);
path, NULL, NULL, NULL, NULL, NULL);
if (hService) { if (hService) {
ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &descr); ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &descr);
} else { } else {
show_error(); show_error();
} }
} else if (action == ID_REMOVE_SERVICE) { } else if (action == ID_REMOVE_SERVICE) {
if ((hService = OpenService(hSCM, service_name, DELETE)) == NULL || if ((hService = OpenServiceW(hSCM, service_name, DELETE)) == NULL ||
!DeleteService(hService)) { !DeleteService(hService)) {
show_error(); show_error();
} }
} else if ((hService = OpenService(hSCM, service_name, } else if ((hService = OpenServiceW(hSCM, service_name,
SERVICE_QUERY_STATUS)) == NULL) { SERVICE_QUERY_STATUS)) == NULL) {
success = 0; success = 0;
} }
...@@ -906,15 +904,15 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, ...@@ -906,15 +904,15 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
{NULL, NULL} {NULL, NULL}
}; };
int service_installed; int service_installed;
char buf[200], *service_argv[] = {__argv[0], NULL}; char buf[200], *service_argv[] = {NULL, NULL};
POINT pt; POINT pt;
HMENU hMenu; HMENU hMenu;
static UINT s_uTaskbarRestart; // for taskbar creation static UINT s_uTaskbarRestart; // for taskbar creation
switch (msg) { switch (msg) {
case WM_CREATE: case WM_CREATE:
if (__argv[1] != NULL && if (my_argv[1] != NULL && !strcmp(my_argv[1], "--")) {
!strcmp(__argv[1], service_magic_argument)) { service_argv[0] = my_argv[0];
start_mongoose(1, service_argv); start_mongoose(1, service_argv);
hThread = mg_start_thread(serving_thread_func, server); hThread = mg_start_thread(serving_thread_func, server);
StartServiceCtrlDispatcher(service_table); StartServiceCtrlDispatcher(service_table);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment