From 07a22181da5aa0b41cdbd5b7a599a8d31860197a Mon Sep 17 00:00:00 2001 From: Lukas W Date: Sun, 26 Nov 2017 14:08:15 +0100 Subject: [PATCH] RemoteVstPlugin: Debug LoadLibrary failure --- plugins/vst_base/RemoteVstPlugin.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plugins/vst_base/RemoteVstPlugin.cpp b/plugins/vst_base/RemoteVstPlugin.cpp index b8c05d528..b95935c2c 100644 --- a/plugins/vst_base/RemoteVstPlugin.cpp +++ b/plugins/vst_base/RemoteVstPlugin.cpp @@ -117,6 +117,25 @@ RemoteVstPlugin * __plugin = NULL; HWND __MessageHwnd = NULL; +//Returns the last Win32 error, in string format. Returns an empty string if there is no error. +std::string GetErrorAsString(DWORD errorMessageID) +{ + //Get the error message, if any. + if(errorMessageID == 0) + return std::string(); //No error message has been recorded + + LPSTR messageBuffer = nullptr; + size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); + + std::string message(messageBuffer, size); + + //Free the buffer. + LocalFree(messageBuffer); + + return message; +} + class RemoteVstPlugin : public RemotePluginClient { @@ -785,6 +804,8 @@ bool RemoteVstPlugin::load( const std::string & _plugin_file ) { if( ( m_libInst = LoadLibraryW( toWString(_plugin_file).c_str() ) ) == NULL ) { + DWORD error = GetLastError(); + debugMessage( "LoadLibrary failed: " + GetErrorAsString(error) ); // give VstPlugin class a chance to start 32 bit version of RemoteVstPlugin if( GetLastError() == ERROR_BAD_EXE_FORMAT ) {