#include "nssm.h"\r
\r
+#define NSSM_SOURCE _T("nssm")\r
#define NSSM_ERROR_BUFSIZE 65535\r
#define NSSM_NUM_EVENT_STRINGS 16\r
unsigned long tls_index;\r
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
TCHAR *strings[NSSM_NUM_EVENT_STRINGS];\r
\r
/* Open event log */\r
- HANDLE handle = RegisterEventSource(0, NSSM);\r
+ HANDLE handle = RegisterEventSource(0, NSSM_SOURCE);\r
if (! handle) return;\r
\r
/* Log it */\r
}\r
\r
/* Show a GUI dialogue */\r
-int popup_message(unsigned int type, unsigned long id, ...) {\r
+int popup_message(HWND owner, unsigned int type, unsigned long id, ...) {\r
va_list arg;\r
\r
TCHAR *format = message_string(id);\r
if (! format) {\r
- return MessageBox(0, _T("Message %lu was supposed to go here!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
+ return MessageBox(0, _T("The message which was supposed to go here is missing!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
}\r
\r
- TCHAR blurb[256];\r
+ TCHAR blurb[NSSM_ERROR_BUFSIZE];\r
va_start(arg, id);\r
- if (_vsntprintf_s(blurb, sizeof(blurb), _TRUNCATE, format, arg) < 0) {\r
+ if (_vsntprintf_s(blurb, _countof(blurb), _TRUNCATE, format, arg) < 0) {\r
va_end(arg);\r
LocalFree(format);\r
- return MessageBox(0, _T("Message %lu was supposed to go here!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
+ return MessageBox(0, _T("The message which was supposed to go here is too big!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
}\r
va_end(arg);\r
\r
- int ret = MessageBox(0, blurb, NSSM, type);\r
+ MSGBOXPARAMS params;\r
+ ZeroMemory(¶ms, sizeof(params));\r
+ params.cbSize = sizeof(params);\r
+ params.hInstance = GetModuleHandle(0);\r
+ params.hwndOwner = owner;\r
+ params.lpszText = blurb;\r
+ params.lpszCaption = NSSM;\r
+ params.dwStyle = type;\r
+ if (type == MB_OK) {\r
+ params.dwStyle |= MB_USERICON;\r
+ params.lpszIcon = MAKEINTRESOURCE(IDI_NSSM);\r
+ }\r
+\r
+ int ret = MessageBoxIndirect(¶ms);\r
\r
LocalFree(format);\r
\r