From 502e1191d50bc7c496a2c0cb2d54d4cf87b586c9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 10 Jan 2008 19:05:59 +0000 Subject: [PATCH] fixed FormatMessage() misuse and improver error handling --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40613 --- sourcemm/metamod_oslink.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/sourcemm/metamod_oslink.cpp b/sourcemm/metamod_oslink.cpp index 42f1517..6d02bcd 100644 --- a/sourcemm/metamod_oslink.cpp +++ b/sourcemm/metamod_oslink.cpp @@ -27,19 +27,31 @@ #include "metamod_oslink.h" #include +#include #ifdef __linux #include -#include #endif #if defined __WIN32__ || defined _WIN32 || defined WIN32 const char *dlerror() { static char buf[1024]; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &buf, 0, NULL); + DWORD num; + + num = GetLastError(); + + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + num, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, + sizeof(buf), + NULL) + == 0) + { + _snprintf(buf, sizeof(buf), "unknown error %x", num); + } + return buf; } #endif