X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=event.cpp;h=4af50a86a925399aa93c8d4835742406c6f7ad84;hb=4d0f8abd0f891348080589ffacd1b9f1fd3faf41;hp=bd06363d53e47fd68cc0003f112d3e20d3dce8d0;hpb=5b9e64a9ae1fbf1254c9c246e5b123d3aa77a37a;p=nssm.git diff --git a/event.cpp b/event.cpp index bd06363..4af50a8 100644 --- a/event.cpp +++ b/event.cpp @@ -14,8 +14,10 @@ TCHAR *error_string(unsigned long error) { TlsSetValue(tls_index, (void *) error_message); } - if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) { - if (_sntprintf_s(error_message, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0; + if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, GetUserDefaultLangID(), (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) { + if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) { + if (_sntprintf_s(error_message, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0; + } } return error_message; } @@ -23,9 +25,11 @@ TCHAR *error_string(unsigned long error) { /* Convert message code to format string */ TCHAR *message_string(unsigned long error) { TCHAR *ret; - 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)) { - ret = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, 32 * sizeof(TCHAR)); - if (_sntprintf_s(ret, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0; + if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, GetUserDefaultLangID(), (LPTSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) { + if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, (LPTSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) { + ret = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, 32 * sizeof(TCHAR)); + if (_sntprintf_s(ret, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0; + } } return ret; } @@ -73,15 +77,15 @@ int popup_message(unsigned int type, unsigned long id, ...) { TCHAR *format = message_string(id); if (! format) { - return MessageBox(0, _T("Message %lu was supposed to go here!"), NSSM, MB_OK | MB_ICONEXCLAMATION); + return MessageBox(0, _T("The message which was supposed to go here is missing!"), NSSM, MB_OK | MB_ICONEXCLAMATION); } - TCHAR blurb[256]; + TCHAR blurb[1024]; va_start(arg, id); - if (_vsntprintf_s(blurb, sizeof(blurb), _TRUNCATE, format, arg) < 0) { + if (_vsntprintf_s(blurb, _countof(blurb), _TRUNCATE, format, arg) < 0) { va_end(arg); LocalFree(format); - return MessageBox(0, _T("Message %lu was supposed to go here!"), NSSM, MB_OK | MB_ICONEXCLAMATION); + return MessageBox(0, _T("The message which was supposed to go here is too big!"), NSSM, MB_OK | MB_ICONEXCLAMATION); } va_end(arg);