diff --git a/linux/VSTPlugin-linux.cpp b/linux/VSTPlugin-linux.cpp index 6d0bd4411..b19d04bcf 100644 --- a/linux/VSTPlugin-linux.cpp +++ b/linux/VSTPlugin-linux.cpp @@ -23,20 +23,49 @@ along with this program. If not, see . AEffect* VSTPlugin::loadEffect() { AEffect *plugin = nullptr; - wchar_t *wpath; - os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath); - soHandle = LoadLibraryW(wpath); + // Why is this a (non-portable) wide char? + wchar_t *wpath = NULL; + + // We need to convert the above wide char to a 'normal' char + // 4096 elements should be enough to contain it... I hope. + // We also initialize the array with NULLs to prevent issues + // down the road. + char charPath[4096] = {NULL}; + uint32_t wcs_returnValue; + //os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath); + wcs_returnValue = wcstombs(charPath, wpath, sizeof(charPath)); + + // Now check for errors in the conversion before trying to open + // the file/path. + if (wcs_returnValue < 4) { + wprintf(L"Path conversion error from '%s'", wpath); + printf(", to '%s'\n", charPath); + return nullptr; + } + + soHandle = os_dlopen(charPath); bfree(wpath); + bfree(charPath); if(soHandle == nullptr) { printf("Failed trying to load VST from '%s', error %d\n", - pluginPath, GetLastError()); + pluginPath.c_str(), errno); return nullptr; } vstPluginMain mainEntryPoint = - (vstPluginMain)GetProcAddress(soHandle, "VSTPluginMain"); + (vstPluginMain)(soHandle, "VSTPluginMain"); + + if (mainEntryPoint == nullptr) { + mainEntryPoint = + (vstPluginMain)os_dlsym(soHandle, "VstPluginMain()"); + } + + if (mainEntryPoint == nullptr) { + mainEntryPoint = (vstPluginMain)os_dlsym(soHandle, "main"); + } - if (!mainEntryPoint) { + if (mainEntryPoint == nullptr) { + printf("Couldn't get a pointer to plugin's main()"); return nullptr; }