PDA

View Full Version : Cannot load DLL.



cmp1104
4th April 2013, 17:27
I am using Qt 4.7 on a Windows 7, 64-bit machine. I am trying to load a third party DLL. In their source file they call LoadLibraryA(functionName) to load the library at run time. The code checks for a handle returned when the DLL is loaded.

This is my problem: Every time I run my code it gets to the point of loading the library but the returned handle value is NULL. This causes the program to crash (Segmentation fault). In my application output window I get "(Internal error: pc 0x0 in read in psymtab, but not in symtab.)".

The twists: Originally another programmer integrated the third party code into the application and the application runs just fine on his machine. I am using his code exactly and I get the crash. I tried the application on a 32-bit laptop. Originally it did not work. However when I uninstalled Qt 4.7 and reinstalled it, the application works. (This may be a red herring....)

Debugs I have tried: 1) I have tried using Dependency Walker. The results I get when I run DW on my application exe are the same ones he gets. 2) I have uninstalled and re-installed Qt on my machine 3) I have verified that the DLL is in the same directory as the executable

Any thoughts?

Thanks.

d_stranz
4th April 2013, 20:02
Is your Qt app compiled as a 64-bit app? Is the third-party DLL a 64-bit DLL? On Windoze 7, all executable parts (exe, dll, etc.) must be all 64-bit or all 32-bit. You can't mix and match 64-bit and 32-bit like you could with 32-bit and 16-bit code on Windows XP.

If the 3rd-party DLL is 32-bit, try recompiling your app (and Qt) in 32-bit mode (or get someone else to do it with a 32-bit compiler and Qt) and see if that makes a difference. A 32-bit app with all dependencies also 32-bit will run just fine on Win 7.

cmp1104
4th April 2013, 21:49
Is your Qt app compiled as a 64-bit app? Is the third-party DLL a 64-bit DLL? On Windoze 7, all executable parts (exe, dll, etc.) must be all 64-bit or all 32-bit. You can't mix and match 64-bit and 32-bit like you could with 32-bit and 16-bit code on Windows XP.

The third party DLL is a 32-bit DLL. I am relatively new to all of the nuances for compiling applications, but I believe that my app is being compiled as 32 bit. In my Project settings, my qmake command line is: "qmake.exe My_App.pro -r -spec win32-g++" and my make command line is: "mingw32-make.exe -w in C:\My_App_Build_Directory".


If the 3rd-party DLL is 32-bit, try recompiling your app (and Qt) in 32-bit mode (or get someone else to do it with a 32-bit compiler and Qt) and see if that makes a difference. A 32-bit app with all dependencies also 32-bit will run just fine on Win 7.
The other computer on which I can get this to work is a 32-bit machine. I checked the qmake and make command lines on this machine and they are the same as on the machine on which the app does not work.

I went back to Dependency Walker to check again for missing dependencies. DW showed that the third party DLL needed "msvcr100d.dll" and "msvcp100d.dll" and that I was missing these. I believe they are part of MS Visual Studio. I already have MSVS Redistribution for 32-bit and 64-bit installed on my machine but apparently these files don't come with the redistribution package. I was able to get the two DLL's from a co-worker that does have the full MSVS install and I put them in my windows\system32 directory. Dependency Walker shows that the DLLs found (though it does not indicate they are 64-bit). Even with these two DLLs in place the app still crashes.

Added after 1 7 minutes:

Okay, I think it is working now. I ended up installing a demo version of MS Visual Studio 2010. Now the DLL loads and runs. I returned to using Dependency Walker and compared the DW output for from the computer that the application worked on and my computer and found two missing MSVC files that I hadn't noticed before. I had installed the redistributable package earlier but apparently it doesn't put these files in place for you.

amleto
5th April 2013, 00:45
The third party DLL is a 32-bit DLL. I am relatively new to all of the nuances for compiling applications, but I believe that my app is being compiled as 32 bit. In my Project settings, my qmake command line is: "qmake.exe My_App.pro -r -spec win32-g++" and my make command line is: "mingw32-make.exe -w in C:\My_App_Build_Directory".


The other computer on which I can get this to work is a 32-bit machine. I checked the qmake and make command lines on this machine and they are the same as on the machine on which the app does not work.

I went back to Dependency Walker to check again for missing dependencies. DW showed that the third party DLL needed "msvcr100d.dll" and "msvcp100d.dll" and that I was missing these. I believe they are part of MS Visual Studio. I already have MSVS Redistribution for 32-bit and 64-bit installed on my machine but apparently these files don't come with the redistribution package. I was able to get the two DLL's from a co-worker that does have the full MSVS install and I put them in my windows\system32 directory. Dependency Walker shows that the DLLs found (though it does not indicate they are 64-bit). Even with these two DLLs in place the app still crashes.

Added after 1 7 minutes:

Okay, I think it is working now. I ended up installing a demo version of MS Visual Studio 2010. Now the DLL loads and runs. I returned to using Dependency Walker and compared the DW output for from the computer that the application worked on and my computer and found two missing MSVC files that I hadn't noticed before. I had installed the redistributable package earlier but apparently it doesn't put these files in place for you.

sharing the debug versions of those dlls is not allowed! You are breaking terms of services and copyright etc.

The solution is to stop using debug versions and use release build for deployment.