PDA

View Full Version : QLibrary::load: The specified module could not be found



mentalmushroom
27th September 2011, 11:49
Hello. I am using QLibrary to load a dll file on Windows 7 x64, but it fails with the error message "The specified module could not be found". WinAPI function LoadLibrary also fails, however, I can load it with
LoadLibraryEx("C:\\Program Files (x86)\\VideoLAN\\VLC\\libvlc.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH) so the problem is somehow related to the search strategy specified with LOAD_WITH_ALTERED_SEARCH_PATH flag. I'd like my code to be cross-platform, so I am trying to use Qt instead of WinAPI, but how can I make it work with QLibrary?

llev
27th September 2011, 15:40
Could you paste here those non-working code(the code using QLibrary and the code using LoadLibrary)?

mentalmushroom
27th September 2011, 15:53
Ok, here it is:


#include <QtCore/QCoreApplication>
#include <QLibrary>

#include <stdio.h>
#include <windows.h>

#define MY_DLL_PATH "C:\\Program Files (x86)\\VideoLAN\\VLC\\libvlc.dll"

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QLibrary qlib(MY_DLL_PATH);
if (qlib.load())
printf("loaded successfully with QLibrary\n");
else printf("failed to load with QLibrary\n");

if (HMODULE hMod = LoadLibraryExA(MY_DLL_PATH, NULL, LOAD_WITH_ALTERED_SEARCH_PATH))
printf("loaded successfully with LoadLibraryEx");
else printf("failed to load with LoadLibraryEx");

return a.exec();
}

llev
27th September 2011, 16:40
Well I suspect you can't work this issue out by Qt API, i.e. keep your app cross-platform. :)
I see the libvlc.dll problem is in that it has dependencies in the same directory(C:\Program Files (x86)\VideoLAN\VLC) which is not a part of default dll search paths.
To make your app looking more cross-platform I would suggest you to call SetDllDirectory (http://msdn.microsoft.com/en-us/library/ms686203.aspx) WinAPI and then load libvlc by using QLibrary:


#if defined( Q_WS_WIN )
SetDllDirectory( L"C:\\Program Files (x86)\\VideoLAN\\VLC" );
#endif

QLibrary lib( "libvlc" );

if ( lib.load() )
{
qDebug() << "libvlc loaded";
}
else
{
qDebug() << "libvlc not loaded";
}

ChrisW67
28th September 2011, 04:05
I am not intimate with the VLC library, but here are some other possible options:

Explicitly load the other DLLs from the VLC directory before the main one.
Change directory to the VLC libs directory and load the main library (then change back). The current directory is in the Windows DLL search path so its dependencies should be found.

sarraf
13th November 2013, 17:32
Check both VLC DLLs and your main program built in same configuration (RELEASE or DEBUG). If your main program is in DEBUG configuration, VLC DLLs should also be in DEBUG configuration.