UnsatisifiedLinkError - Unable to load dependent libraries - c++

I have developed a Java applet that loads my C++ dll through the loadLibrary function. From there, my applet calls some native methods that are implemented in the C++ code. I have created an InstallShield installer that puts the C++ dll in the required location on my client computers.
Everything works just fine on my development PC, but when I try testing on a "fresh" client computer that does not have anything but the JRE installed, I am getting an UnsatisfiedLinkError: Can't find dependent libraries. I don't know if there is something else I need to include. I checked using DependencyWalker and below is what I saw.
Is there anything out of the ordinary that a fresh windows install would not include? What else can I do to determine what dependency my dll cannot find on the client?

Related

Q: Proper way to access data in a data only dll file

My application store some data in data only dll files. Those dll files are loaded with LoadLibrary() when needed at runtime and then discarded with FreeLibrary() after finish using them. The main application access the data stored in the dll files using GetProcAddress(). The program is written in C++ and uses WinAPI calls, no MFC or other libraries. It has two versions x64 and x86. It works fine on most systems. My dll files do not call other libraries or depend on anything else. Each is a stand alone file.
Recently, I discovered the program does not work on one machine. this specific one has Windows 10 x64 installed on it. After investigations I found the following:
LoadLibrary() fails with error message "Could not find module". The dll is in same directory with main program.
I replaced the call to LoadLibrary() with LoadLibraryEx() and tried the following falgs:
LOAD_IGNORE_CODE_AUTHZ_LEVEL did not work. The dll could not be loaded.
DONT_RESOLVE_DLL_REFERENCES ... works?? But, Microsoft strongly recommends not to use it.
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE ... loading the dll succeeds?? But, the call to GetProcessAddress later fails. the program could not access the data in the dll file. So this is not actually working.
I could not find anything wrong with this machine. All other programs are working fine.
I tried the x86 version on this machine and it worked fine using original LoadLibrary().
My installer is dual system and automatically installs x64 version when it finds x64 windows. Normal user can not simply switch to x86 when he gets such error.
My question is how can I eliminate this error and make my program works on any machine:
Should I call LoadLibraryEx() using DONT_RESOLVE_DLL_REFERENCES flag and ignore Microsoft warning?
Is there any way I can get my library loaded with simple call to LoadLibrary()?
If I call LoadLibraryEx() with LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE flag, as recommended by Microsoft, how can I access the data without calling GetProcessAddress()?
Thank you in advance.

DLL Hell with Intel Redistributables

Some of our users have been complaining about a libmmd.dll not found error on our plugins loading.
Some background:
I'm talking about an issue occurring on Windows (8, for that matter).
We develop plugins for Digital Audio Workstations (for digital sound
processing purposes).
Our plugin is a DLL coded in VS2012 and compiled with Intel Compiler 2015 via Perl scripts calling icl.exe
from the cmd.
One of its dependencies is an Intel-supplied math
library provided in the 2015 flavor of its redistributables (which we
install together with our plugins) called libmmd.dll.
For a matter of convenience, let's call the plugin DLL plugin.dll (!!!).
I didn't have much time on one of the affected users' machine but from what I saw, reinstalling Intel's redistributables package didn't help, only moving libmmd.dll to the same folder as plugin.dll.
Whatever the reason for this (sudden and unexpected) behavior, we want to be able to deliver software protected against this kind of issues (DLL Hell).
What we want is for plugin.dll to look for libraries first in a specific directory (configurable would be even better), then in its usual search order.
I tried playing with manifests, registry, library names, linker options...
The only things that actually worked were switching the /MD option with /MT (but recompiling with static libs really adds to the size of plugin.dll) and copying the library to the folder plugin.dll is in.
Any ideas ?
Thanks !
The SetDllDirectory function lets you add a folder path to the DLL search order. It will be added in second place, immediately behind the program folder itself.
This only affects DLLs loaded via LoadLibrary however; if your DLLs are loaded statically it won't make any difference.

DllNotFoundException for C++ library from .NET app on some computers

We have .NET application which uses C++ library via [DllImport]. It works fine on many computers (thousands of customers) excepting 3 computers. All of them have Windows 10 installed (other Windows 10 platforms work fine).
The exception is:
System.DllNotFoundException: Unable to load DLL 'Helper.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
This dll places in the same folder as main executable file.
What already done to fix:
put DLL in system32 folder;
installed different version of vc redist;
run as administrator.
The result is the same.
Any ideas, guys?
Thanks in advance!
Don't put the DLL in the system directory. You aren't supposed to put files there. Put the DLL in the same directory as the executable.
If you do that and the system reports DllNotFoundException that means one of the DLL's dependencies could not be found. Next you need to find out what the dependencies are, and make sure that they are all met.
You can use a tool like Dependency Viewer to check the dependencies, but really the best way to do this is to go to the source. Either the documentation of the library if it is a third party library, or direct from the source code and compilation options if you have built the DLL yourself.

Requests lib and py2exe COM server issue

I'm working in a Com Server DLL where I use requests to make POST a multipart form along with some XML file.
Localy, it works great and with no error. I can call the COM object methods and it returns me what I'm expeting to.
Now, when I use py2exe to build a dist version of the app, and try to register the DLL Com Server with regsvr32, I get the following error:
"Runtime Error!
...
R6034
An application has made an attempt to load the C runtime library incorrecly.
..."
Also, I've noticed that if I remove any reference to the requests library in my python code, I don't get this issue (obviously, I've lost the main functionality of the module).
I tried distributing the C runtime DLLs with the manifest solution in every possible flavor. Also installed the runtime from the microsoft redistributable installer. No effects whatsoever. I'm possitively sure that it's got nothing to do with the runtime itself.
Made virtual machines with W7 and XP, for testing purposes. I can register the Com server with regsvr32, but the error occurs when calling the method.
However, if I comment the line where I make the POST with the request lib, or if I call another method where request is not involved, no errors occurs and everything seems to be working fine. Of course, the key functionality of the COM is lost, since everything revolves around the request lib. And I sincerely don't want to use the primitive urllib lib...
My conclusion: seems to be something with py2exe and the request lib. Some dependency has to be missing. Although I can't figure what or why, since py2exe seems to be packing everything...
Never before has any problem distributing COM servers with py2exe.
Has anyone had any similar problem with py2exe and requests???
Seems very similar to py2exe com dll problem. Perhaps its just a matter of packaging the C Runtime DLL, or installing the Visual C++ 2008 Redistributable on the machines you are deploying to.

Packaging a jre with my application

My application contains an c++ exe file which invokes a java program using JNI, thus requiring jvm.dll. However, I want my application to ship with its own embedded jre but after I copy the jre6 folder found in JAVA_HOME and added it to my installer, it fails to run the program(Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries), when I use dependency walker on jvm.dll, it says that it can't find gpsvc.dll, IEShims.dll and sysntfy.dll. After I tried copying those dlls to the same folder as jvm.dll, dependency walker tells me that gpsvc.dll andsysntfy.dll is 64 bit where it should be x86. Problem is, those were the only dlls on my system, what should I do?
The Java virtual machine consists of much more than just jvm.dll. You'll need to redistribute the whole JVM package and install that on a user's machine instead of just adding jvm.dll to your own application.
It will probably be much easier to require your users to download and install the JVM themselves before installing your application. If you really want to redistribute the JVM with your application, you'll need to find documentation on Oracle's website on what the exact license for that is and on how to do it. Look at this paragraph of the JDK 6 readme, for example.
It's not as simple as copying jvm.dll and other libraries that it depends on.
You may download the required dll's from the appropriate sites, i.e. from this one.