TlsSetValue(tls_index, (void *) error_message);\r
}\r
\r
- if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) {\r
- if (_sntprintf_s(error_message, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0;\r
+ if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, GetUserDefaultLangID(), (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) {\r
+ if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) {\r
+ if (_sntprintf_s(error_message, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0;\r
+ }\r
}\r
return error_message;\r
}\r
/* Convert message code to format string */\r
TCHAR *message_string(unsigned long error) {\r
TCHAR *ret;\r
- if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) {\r
- ret = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, 32 * sizeof(TCHAR));\r
- if (_sntprintf_s(ret, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0;\r
+ if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, GetUserDefaultLangID(), (LPTSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) {\r
+ if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, (LPTSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) {\r
+ ret = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, 32 * sizeof(TCHAR));\r
+ if (_sntprintf_s(ret, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0;\r
+ }\r
}\r
return ret;\r
}\r
static HWND tablist[NSSM_NUM_TABS];\r
static int selected_tab;\r
\r
+static HWND dialog(const TCHAR *templ, HWND parent, DLGPROC function, LPARAM l) {\r
+ /* The caller will deal with GetLastError()... */\r
+ HRSRC resource = FindResourceEx(0, RT_DIALOG, templ, GetUserDefaultLangID());\r
+ if (! resource) {\r
+ if (GetLastError() != ERROR_RESOURCE_LANG_NOT_FOUND) return 0;\r
+ resource = FindResourceEx(0, RT_DIALOG, templ, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));\r
+ if (! resource) return 0;\r
+ }\r
+\r
+ HGLOBAL ret = LoadResource(0, resource);\r
+ if (! ret) return 0;\r
+\r
+ return CreateDialogIndirectParam(0, (DLGTEMPLATE *) ret, parent, function, l);\r
+}\r
+\r
+static HWND dialog(const TCHAR *templ, HWND parent, DLGPROC function) {\r
+ return dialog(templ, parent, function, 0);\r
+}\r
+\r
int nssm_gui(int resource, nssm_service_t *service) {\r
/* Create window */\r
- HWND dlg = CreateDialogParam(0, MAKEINTRESOURCE(resource), 0, nssm_dlg, (LPARAM) service);\r
+ HWND dlg = dialog(MAKEINTRESOURCE(resource), 0, nssm_dlg, (LPARAM) service);\r
if (! dlg) {\r
popup_message(MB_OK, NSSM_GUI_CREATEDIALOG_FAILED, error_string(GetLastError()));\r
return 1;\r
tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_APPLICATION, (LPARAM) &tab);\r
if (service->native) {\r
- tablist[NSSM_TAB_APPLICATION] = CreateDialog(0, MAKEINTRESOURCE(IDD_NATIVE), window, tab_dlg);\r
+ tablist[NSSM_TAB_APPLICATION] = dialog(MAKEINTRESOURCE(IDD_NATIVE), window, tab_dlg);\r
EnableWindow(tablist[NSSM_TAB_APPLICATION], 0);\r
EnableWindow(GetDlgItem(tablist[NSSM_TAB_APPLICATION], IDC_PATH), 0);\r
}\r
- else tablist[NSSM_TAB_APPLICATION] = CreateDialog(0, MAKEINTRESOURCE(IDD_APPLICATION), window, tab_dlg);\r
+ else tablist[NSSM_TAB_APPLICATION] = dialog(MAKEINTRESOURCE(IDD_APPLICATION), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_APPLICATION], SW_SHOW);\r
\r
/* Details tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_DETAILS);\r
tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_DETAILS, (LPARAM) &tab);\r
- tablist[NSSM_TAB_DETAILS] = CreateDialog(0, MAKEINTRESOURCE(IDD_DETAILS), window, tab_dlg);\r
+ tablist[NSSM_TAB_DETAILS] = dialog(MAKEINTRESOURCE(IDD_DETAILS), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_DETAILS], SW_HIDE);\r
\r
/* Set defaults. */\r
tab.pszText = message_string(NSSM_GUI_TAB_LOGON);\r
tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_LOGON, (LPARAM) &tab);\r
- tablist[NSSM_TAB_LOGON] = CreateDialog(0, MAKEINTRESOURCE(IDD_LOGON), window, tab_dlg);\r
+ tablist[NSSM_TAB_LOGON] = dialog(MAKEINTRESOURCE(IDD_LOGON), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_LOGON], SW_HIDE);\r
\r
/* Set defaults. */\r
tab.pszText = message_string(NSSM_GUI_TAB_SHUTDOWN);\r
tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_SHUTDOWN, (LPARAM) &tab);\r
- tablist[NSSM_TAB_SHUTDOWN] = CreateDialog(0, MAKEINTRESOURCE(IDD_SHUTDOWN), window, tab_dlg);\r
+ tablist[NSSM_TAB_SHUTDOWN] = dialog(MAKEINTRESOURCE(IDD_SHUTDOWN), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_SHUTDOWN], SW_HIDE);\r
\r
/* Set defaults. */\r
tab.pszText = message_string(NSSM_GUI_TAB_EXIT);\r
tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_EXIT, (LPARAM) &tab);\r
- tablist[NSSM_TAB_EXIT] = CreateDialog(0, MAKEINTRESOURCE(IDD_APPEXIT), window, tab_dlg);\r
+ tablist[NSSM_TAB_EXIT] = dialog(MAKEINTRESOURCE(IDD_APPEXIT), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_EXIT], SW_HIDE);\r
\r
/* Set defaults. */\r
tab.pszText = message_string(NSSM_GUI_TAB_IO);\r
tab.cchTextMax = (int) _tcslen(tab.pszText) + 1;\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_IO, (LPARAM) &tab);\r
- tablist[NSSM_TAB_IO] = CreateDialog(0, MAKEINTRESOURCE(IDD_IO), window, tab_dlg);\r
+ tablist[NSSM_TAB_IO] = dialog(MAKEINTRESOURCE(IDD_IO), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_IO], SW_HIDE);\r
\r
/* Rotation tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_ROTATION);\r
tab.cchTextMax = (int) _tcslen(tab.pszText) + 1;\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_ROTATION, (LPARAM) &tab);\r
- tablist[NSSM_TAB_ROTATION] = CreateDialog(0, MAKEINTRESOURCE(IDD_ROTATION), window, tab_dlg);\r
+ tablist[NSSM_TAB_ROTATION] = dialog(MAKEINTRESOURCE(IDD_ROTATION), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_ROTATION], SW_HIDE);\r
\r
/* Set defaults. */\r
tab.pszText = message_string(NSSM_GUI_TAB_ENVIRONMENT);\r
tab.cchTextMax = (int) _tcslen(tab.pszText) + 1;\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_ENVIRONMENT, (LPARAM) &tab);\r
- tablist[NSSM_TAB_ENVIRONMENT] = CreateDialog(0, MAKEINTRESOURCE(IDD_ENVIRONMENT), window, tab_dlg);\r
+ tablist[NSSM_TAB_ENVIRONMENT] = dialog(MAKEINTRESOURCE(IDD_ENVIRONMENT), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_ENVIRONMENT], SW_HIDE);\r
\r
return 1;\r