3 /* Convert error code to error string - must call LocalFree() on return value */
\r
4 char *error_string(unsigned long error) {
\r
5 static char message[65535];
\r
6 if (! FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, 0, NSSM_MESSAGE_DEFAULT, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), message, sizeof(message), 0)) return 0;
\r
10 /* Log a message to the Event Log */
\r
11 void eventprintf(unsigned short type, unsigned long id, char *format, ...) {
\r
17 /* Construct the message */
\r
18 size = sizeof(message);
\r
19 va_start(arg, format);
\r
20 n = _vsnprintf(message, size, format, arg);
\r
24 if (n < 0 || n >= size) return;
\r
26 /* Construct strings array */
\r
27 strings[0] = message;
\r
30 /* Open event log */
\r
31 HANDLE handle = RegisterEventSource(0, TEXT(NSSM));
\r
32 if (! handle) return;
\r
35 if (! ReportEvent(handle, type, 0, id, 0, 1, 0, (const char **) strings, 0)) {
\r
36 printf("ReportEvent(): %s\n", error_string(GetLastError()));
\r
39 /* Close event log */
\r
40 DeregisterEventSource(handle);
\r