Permalink
Browse files

Win32: Rewrite the service wrapper

Edited original commit to pass MAX_PATH as nSize to GetModuleFileNameA() instead of 101 after approval from author @ChrisTX (Attila Molnar)

Fixes #404 reported by @crchauffe
  • Loading branch information...
ChrisTX authored and attilamolnar committed Mar 23, 2013
1 parent f2a5fa5 commit 25aa23067133fa80df009c2245742b3b7749c2e5
Showing with 208 additions and 278 deletions.
  1. +22 −0 win/inspircd_win32wrapper.cpp
  2. +15 −0 win/inspircd_win32wrapper.h
  3. +168 −274 win/win32service.cpp
  4. +3 −4 win/win32service.h
@@ -180,6 +180,28 @@ int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, cons
return 1;
}
+CWin32Exception::CWin32Exception() : exception()
+{
+ dwErrorCode = GetLastError();
+ if( FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)szErrorString, _countof(szErrorString), NULL) == 0 )
+ sprintf_s(szErrorString, _countof(szErrorString), "Error code: %u", dwErrorCode);
+}
+
+CWin32Exception::CWin32Exception(const CWin32Exception& other)
+{
+ strcpy_s(szErrorString, _countof(szErrorString), other.szErrorString);
+}
+
+const char* CWin32Exception::what() const throw()
+{
+ return szErrorString;
+}
+
+DWORD CWin32Exception::GetErrorCode()
+{
+ return dwErrorCode;
+}
+
#include "../src/modules/m_spanningtree/link.h"
#include "../src/modules/ssl.h"
template class reference<Link>;
@@ -186,5 +186,20 @@ void ::operator delete(void * ptr);
#define DISABLE_WRITEV
+#include <exception>
+
+class CWin32Exception : public std::exception
+{
+public:
+ CWin32Exception();
+ CWin32Exception(const CWin32Exception& other);
+ virtual const char* what() const throw();
+ DWORD GetErrorCode();
+
+private:
+ char szErrorString[500];
+ DWORD dwErrorCode;
+};
+
#endif
Oops, something went wrong.

0 comments on commit 25aa230

Please sign in to comment.