3 static char error_message[65535];
\r
5 /* Convert error code to error string - must call LocalFree() on return value */
\r
6 char *error_string(unsigned long error) {
\r
7 if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char *) &error_message, sizeof(error_message), 0)) {
\r
8 if (_snprintf(error_message, sizeof(error_message), "system error %lu", error) < 0) return 0;
\r
10 return error_message;
\r
13 /* Log a message to the Event Log */
\r
14 void log_event(unsigned short type, unsigned long id, ...) {
\r
20 /* Open event log */
\r
21 HANDLE handle = RegisterEventSource(0, TEXT(NSSM));
\r
22 if (! handle) return;
\r
27 while ((s = va_arg(arg, char *))) strings[count++] = s;
\r
29 ReportEvent(handle, type, 0, id, 0, count, 0, (const char **) strings, 0);
\r
31 /* Close event log */
\r
32 DeregisterEventSource(handle);
\r