X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=event.cpp;fp=event.cpp;h=bd43be3515011535a795000a0812684be853927f;hb=e9d9b2fa71473e96650fe3fc4ee0d5535c6725d8;hp=661761dac8d3ef74aed441a0e313d06118bc6660;hpb=1a0589979826c8388941f753b58ec7f437a3c247;p=nssm.git diff --git a/event.cpp b/event.cpp index 661761d..bd43be3 100644 --- a/event.cpp +++ b/event.cpp @@ -1,5 +1,15 @@ #include "nssm.h" +static char error_message[65535]; + +/* Convert error code to error string - must call LocalFree() on return value */ +char *error_string(unsigned long error) { + if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char *) &error_message, sizeof(error_message), 0)) { + if (_snprintf(error_message, sizeof(error_message), "system error %lu", error) < 0) return 0; + } + return error_message; +} + /* Log a message to the Event Log */ void log_event(unsigned short type, unsigned long id, ...) { va_list arg;