Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infernal Libraries (aka DLL Hell)

In a Project of mine, I use a Delphi Application which dynamically loads a wrapper DLL (exporting C-Style functions) which in turn is statically link against a bunch of 3rd party DLLs.

It works fine on my test machines, but on my customers computer it failed to initialize with an error Message like "Couldn't find entrypoint _somefunction@4AKKZ in TMYlibrary.dll".

After some investigation with sysinternal's process monitor, I realized that Windows would look fror DLLs in windows/sytem32 first, so if a DLL named similar to my DLL was present in system32, windows would pick that one and try to find my function entry points in it - which would fail.

Do you know of a possiblity to change windows' DLL the searching behaviour?


Additional Information

  • [Update] The .exe file is located on the top level of the application's folder tree.
  • The Wrapper and the 3rd-party-DLLs ar e both located in the Subfolder /bin of my apps Folder
  • Dev platform is windows XP/7, using VS2008 for the dlll and Delphi 2010 for the application
like image 931
sum1stolemyname Avatar asked Dec 09 '22 14:12

sum1stolemyname


2 Answers

I found another solution myself:

SetDllDirectory adds an additional search path to the list of locations to look at.

From http://msdn.microsoft.com/en-us/library/ms686203%28v=VS.85%29.aspx

After calling SetDllDirectory, the DLL search path is:

  1. The directory from which the application loaded.
  2. The directory specified by the lpPathName parameter.
  3. The system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is System32.
  4. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
  5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  6. The directories that are listed in the PATH environment variable.

(maybe i should do my googling before I post on SO ;)

like image 68
sum1stolemyname Avatar answered Dec 12 '22 04:12

sum1stolemyname


Ship the DLL in your program's folder. (same as the exe file).

Then Windows should try your version first.

like image 35
Alex Avatar answered Dec 12 '22 05:12

Alex