Click here to Skip to main content
15,399,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I am working with VS2017 in C++. I have a 3rd party DLL that I load in my program. When running my program on my PC the DLL is loaded correctly.

I tried to run my program (compiled in release mode) on another PC, but the DLL failed to load - with error 7e - the specified module could not be found.

The DLL is in the same place on both PCs. I opened the DLL in Dependency Walker and there are no red markings - only yellow, and the Dependency Walker result seems the same on both PCs.

I tried to write a tester app that just loads the DLL (using LoadLibrary). In my tester app the DLL is loaded in my PC and fails to load in the second PC with the same reason. The tester is also built in Release mode.

I have an older version of the DLL that succeeds to load on both PCs.

Anyone have any idea why the difference in the behavior of LoadLibaray on both PCs? Can it be related to the fact that the second PC doesn't have any IDE installed on it? If so what should I install to solve this problem?

Both PCs has Microsoft Visual C++ 2015-2019 Redistributable x86 & x64 installed.

Can anyone guess what was done to the DLL when writing its newer version that causes the new version to fail and the old version to work?

Thanks!

dj4400

What I have tried:

Tester Application
Older DLL version
Different PCs
Dependency Walker
Google
Posted
Updated 10-Feb-22 1:55am
v5
Comments
Shao Voon Wong 9-Feb-22 22:58pm
   
Are the 2 PC OS the same? Most probably the new dll needs another dll not present in your other machine.

Get the "Dependency Walker" tool(from Microsoft by Steve Miller) for both 32 and 64 bit. Go to your other failing machine and drop that dll into the Walker window. You should see all the dependencies. If any are missing then you won't be able to load that dll
   
v2
Comments
Rick York 9-Feb-22 18:07pm
   
This is good advice.

dj4400: if you don't want to use that program Visual Studio comes with something called "dumpbin." You can use it with the "/IMPORTS" option and it will tell you all the DLLs you are trying to import. This works with both DLLs and executable files. You might have to transfer it over to your target machine since it's not a built-in utility.
dj4400 10-Feb-22 2:54am
   
Thanks
I opened the DLL in Dependency Walker and there are no red markings - only yellow, and the Dependency Walker result seems the same on both PCs.

I tried using the dumpbin on the target machine but it appears to require the
installation of VS IDE
Randor 10-Feb-22 4:21am
   
What is the DLL path? Check to see if folder redirection applies. If so then have a look at Wow64DisableWow64FsRedirection
Rick York 10-Feb-22 20:46pm
   
You don't need to run dumpbin on the target machine. You need to run it on your development machine and then take note of the libraries that are referenced. You can redirect the output to a file and then analyze the results however you want to.
It has nothing to do with the IDE being installed.

This usually comes down to your code being compiled to target "Any CPU", which means it runs as a 32-bit app on 32-bit Windows and a 64-bit app on 64-bit Windows.

The problem comes down to the library you're loading. If it's a 32-bit only .DLL, it cannot be loaded by a 64-bit process.

So, go into your project properties, Build tab, and change the Platform Target from "Any CPU" to x86 if the .DLL you're trying to load is 32-bit or x64 if the .DLL is 64-bit.
   
Comments
dj4400 9-Feb-22 10:45am
   
Hi Dave,
If there was a problem with a 32 bit dll being loaded on a 64 bit application then the problem should have happened on both PCs. Both PCs run win10 64 bit.

Both my original application and the tester are WIN32.
Dave Kreskowiak 9-Feb-22 10:50am
   
There is no difference in LoadLibrary on both PC's so the problem comes down to your code.

Since we don't know anything about your code, it's pretty much impossible to tell you what's going on.
dj4400 9-Feb-22 11:31am
   
I also thought that may be there is something wrong with my code
so I wrote the Tester. The tester app just calls loadlibrary(str) :

#include "stdafx.h"
#include "windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
char str[260];
HINSTANCE hi;
printf("insert full path");
scanf("%s", &str);
hi = LoadLibrary(str);
if (hi == NULL)
{
printf("Error loading - %d\n", GetLastError());
}

}
Dave Kreskowiak 9-Feb-22 11:47am
   
What are the dependencies the .DLL is looking for? If one of those dependencies on that tree don't exist on the machine, the load is going to fail.
dj4400 9-Feb-22 11:32am
   
The user just enters the full path of the dll
I opened the DLL in Dependency Walker on the target PC and there was no red markings

So i tried the dumpbin in the 1st PC to see what dlls does it use and i saw it was using just 2 dlls. I searched them on the target PC and saw that one WAS missing
I copied it to the target PC and everything works

Thanks All!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900