@@ -51,11 +51,27 @@ static inline void closeHandle(decltype(LoadedLibInfo::handle) handle) {
5151static void errorMsg (const char *file, int line, const char *msg) {
5252
5353#ifdef _WIN32
54- DWORD ret = GetLastError ();
55- if (ret) {
56- fprintf (stderr, " : DLL Error 0x%x" , ret);
57- LOGE (msg, stderr, " : DLL Error 0x%x" , ret);
54+ // DWORD ret = GetLastError();
55+
56+ LPVOID lpMsgBuf;
57+ DWORD dw = GetLastError ();
58+
59+ if (dw) {
60+
61+ FormatMessage (
62+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
63+ FORMAT_MESSAGE_FROM_SYSTEM |
64+ FORMAT_MESSAGE_IGNORE_INSERTS,
65+ NULL ,
66+ dw,
67+ 0 ,
68+ (LPTSTR) &lpMsgBuf,
69+ 0 , NULL );
70+
71+ LOGE (msg, " Error code " , dw, " : " , (LPTSTR)lpMsgBuf);
5872 }
73+ LocalFree (lpMsgBuf);
74+
5975#elif defined(__APPLE__)
6076 // Any additional error messages are logged directly by the system
6177 // and are not available to the application
@@ -194,7 +210,7 @@ void PluginManager::loadPlugins(const File &pluginPath) {
194210
195211 if (res < 0 )
196212 {
197- LOGE (" DLL Load FAILED" );
213+ LOGE (foundDLLs[i]. getFileName (), " Load FAILED" );
198214 }
199215 else
200216 {
@@ -246,7 +262,7 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
246262#endif
247263
248264 if (!handle) {
249- ERROR_MSG (" Failed to load plugin DLL" );
265+ ERROR_MSG (" Failed to load plugin DLL. " );
250266 closeHandle (handle);
251267 return -1 ;
252268 }
@@ -263,7 +279,7 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
263279
264280 if (!infoFunction)
265281 {
266- ERROR_MSG (" Failed to load function 'getLibInfo'" );
282+ ERROR_MSG (" Failed to load function 'getLibInfo'. " );
267283 closeHandle (handle);
268284 return -1 ;
269285 }
@@ -273,7 +289,7 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
273289
274290 if (libInfo.apiVersion != PLUGIN_API_VER)
275291 {
276- std::cerr << pluginLoc << " invalid version" << std::endl ;
292+ ERROR_MSG ( " Invalid Plugin API version" ) ;
277293 closeHandle (handle);
278294 return -1 ;
279295 }
@@ -290,7 +306,7 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
290306
291307 if (!piFunction)
292308 {
293- ERROR_MSG (" Failed to load function 'getPluginInfo'" );
309+ ERROR_MSG (" Failed to load function 'getPluginInfo'. " );
294310 closeHandle (handle);
295311 return -1 ;
296312 }
0 commit comments