QLibrary does not load
-
@
QLibrary lib("C:\A.dll");
@Should be:
@
QLibrary lib("C:\A.dll");
@Use double slash in strings.
-
What is the error string provided by:
@
QLibrary::errorString()
@after you load the library?
-
You could try with the Windows SDK's LoadLibrary function (#include <Windows.h>). Then get the error identifier using GetLastError:
@
#include <Windows.h>
#include <string>
#include <QDebug>std::string getLastErrorAsString();
int main()
{
HMODULE libraryHandle = ::LoadLibrary( "C:\A.dll" );
if ( libraryHandle == 0 )
{
const DWORD errorCode = ::GetLastError();
qDebug() << "error: code(" << errorCode << "), description(" << getLastErrorAsString() << ')';
}return 0;
}
std::string getLastErrorAsString()
{
//Get the error message, if any.
DWORD errorMessageID = ::GetLastError();
if(errorMessageID == 0)
return "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;
}
@ -
Hi,
Can you check "this":http://stackoverflow.com/questions/22354639/loading-library-with-dependency-with-qlibrary out.
-
[quote author="napajejenunedk0" date="1401015515"]You could try with the Windows SDK's LoadLibrary function (#include <Windows.h>). Then get the error identifier using GetLastError:
@
#include <Windows.h>
#include <string>
#include <QDebug>std::string getLastErrorAsString();
int main()
{
HMODULE libraryHandle = ::LoadLibrary( "C:\A.dll" );
if ( libraryHandle == 0 )
{
const DWORD errorCode = ::GetLastError();
qDebug() << "error: code(" << errorCode << "), description(" << getLastErrorAsString() << ')';
}return 0;
}
std::string getLastErrorAsString()
{
//Get the error message, if any.
DWORD errorMessageID = ::GetLastError();
if(errorMessageID == 0)
return "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;
}
@[/quote]the error massage is:
error: code <126>, description<the specified module could not be found. -
Just to be sure: You are not trying to load a 64-Bit DLL from a 32-Bit process or vice versa, right? If so, it clearly cannot work.
Secondly, does your "A.dll" have any further dependencies? Check this with Dependency Walker, if not sure! And make sure that all required dependencies are present! Note that Windows will look for the dependencies in the directory where your EXE file is located and in some system directories (like "C:\Windows\System32"), but not in the directory where "A.dll" is located.
Last but not least: Putting the DLL file directly into "C:" is pretty unusual. Non-elevated processes don't have write-access there. It's even possible the Virtual Store actually copied the DLL to another place, like "C:\Users\UserName\AppData\Local\VirtualStore\A.dll" rather than "C:\A.dll". So in the Explorer it may appear to be stored at "C:\A.dll" while it fact it is not! So try loading the DLL from a more "safe" place, like your "Desktop" directory...