views:

132

answers:

2

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
+1  A: 

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

Then Windows should try your version first.

Alex
That's what he did. Did you read the question? Or did He? The question is ambiguous and does not state where the EXE file is.
Warren P
+11  A: 

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 ;)

sum1stolemyname
+1 because it is always good when someone takes the time to give a correct answer, especially when he was the one who asked for it in the first place :)
ereOn
someone might just google and hit this SO question. Which is useful. So it's worth asking and answering your own question.
Warren P
@warren: Good point. That's actually how i came into contact with this site.
sum1stolemyname