From 1effc94df7e558de6319082e390803911cf45c24 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 12 Jan 2011 19:27:48 +0000 Subject: Plugger, and potentially anything that can use windows, can report windows errors now...uh...woo? --- src/compat/win32.cpp | 22 ++++++++++++++++++++++ src/compat/win32.h | 2 ++ src/plugger.h | 18 ++++++++++-------- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/compat/win32.cpp b/src/compat/win32.cpp index 6fcac15..052644a 100644 --- a/src/compat/win32.cpp +++ b/src/compat/win32.cpp @@ -162,5 +162,27 @@ int Bu::Winsock2::__WSAFDIsSet( SOCKET s, fd_set *set ) { return (*Bu::Winsock2::_fnptr___WSAFDIsSet)( s, set ); } +Bu::FString Bu::getLastWinError() +{ + LPVOID lpMsgBuf; + DWORD dw = GetLastError(); + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &lpMsgBuf, + 0, NULL ); + + Bu::FString sRet( (char *)lpMsgBuf ); + + LocalFree(lpMsgBuf); + + return sRet; +} + #endif diff --git a/src/compat/win32.h b/src/compat/win32.h index 6304d4c..ea0ae53 100644 --- a/src/compat/win32.h +++ b/src/compat/win32.h @@ -89,6 +89,8 @@ namespace Bu static char scode[15]; static char *gai_strerror( int iCode ); }; + + Bu::FString getLastWinError(); }; #ifdef FD_ISSET diff --git a/src/plugger.h b/src/plugger.h index 37d6f19..2780356 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -14,6 +14,8 @@ #include "bu/fstring.h" #include +#include "bu/config.h" + #ifdef WIN32 # include #else @@ -197,29 +199,29 @@ namespace Bu pReg->dlHandle = LoadLibrary( sFName.getStr() ); if( pReg->dlHandle == NULL ) { - throw PluginException( 1, "Error opening %s: %s", sFName.getStr(), - "unknown error, fix this for windows" ); + throw PluginException( 1, "Error opening %s: %s", + sFName.getStr(), Bu::getLastWinError().getStr() ); } pReg->pInfo = (PluginInfo *)GetProcAddress( pReg->dlHandle, sPluginName.getStr() ); if( pReg->pInfo == NULL ) { - throw PluginException( 2, "Error mapping %s: %s", sFName.getStr(), - "unknown error, fix this for windows" ); + throw PluginException( 2, "Error mapping %s: %s", + sFName.getStr(), Bu::getLastWinError().getStr() ); } #else pReg->dlHandle = dlopen( sFName.getStr(), RTLD_NOW ); if( pReg->dlHandle == NULL ) { - throw PluginException( 1, "Error opening %s: %s", sFName.getStr(), - dlerror() ); + throw PluginException( 1, "Error opening %s: %s", + sFName.getStr(), dlerror() ); } pReg->pInfo = (PluginInfo *)dlsym( pReg->dlHandle, sPluginName.getStr() ); if( pReg->pInfo == NULL ) { - throw PluginException( 2, "Error mapping %s: %s", sFName.getStr(), - dlerror() ); + throw PluginException( 2, "Error mapping %s: %s", + sFName.getStr(), dlerror() ); } #endif hPlugin.insert( pReg->pInfo->sID, pReg ); -- cgit v1.2.3