tags:

views:

37

answers:

2

I'm having trouble setting the path to a DLL that is not in the same directory as the executable.

I have a reference to dllA.dll. At present, everything is just copied into the same directory and all is well; however, I need to move the executable to another directory while still referencing the DLL in the original directory.

So, it's setup like:

C:\Original\Dir

program.exe
dllA.dll
dllB.dll
dllC.dll

But I need to have it setup like:

C:\New\Dir

program.exe
dllB.dll
dllC.dl

Such that it is still able to reference dllA.dll in C:\Original\dir

I tried the following, but to no avail:

  • Set the "Copy Local" value to false for dllA.dll because I want it to be referenced in its original location.
  • Under "Tools > Options > Projects and Solutions > VC++ Directories" I have added the path to "C:\Original\Dir"
  • Added "C:\Original\Dir" to both the PATH and LIB environment variables

At runtime, it informs me that it cannot locate dllA.dll Maybe the above steps I took only matter at compile time?

I was able to find this http://stackoverflow.com/questions/1382704/c-specifying-a-location-for-dll-reference

But I was thinking that my above method should've worked.

Any ideas?

A: 

Your compile-time settings won't affect the run-time path. Try adding C:\Original\dir to the system-wide path, and you should see that it picks up the DLL correctly. If so, then your solutions appear to be: 1) modify the system path permanently. May or may not be feasible. 2) alter the environment path at run-time. 3) use relative paths when referring to the DLL. 4) record the path to the DLL at installation time, perhaps in the registry, so that your exe can load it explicitly.

Chris Thornton
"Try adding C:\Original\dir to the system-wide path" If by this, you mean add "C:\Oriignal\dir" to the PATH environment variable, I had initially tried that.
Jesse
A: 

While I may still foolishly believe this can be accomplished through specifying the proper path variables, I was able to overcome this issue by adding some entries to my app.config

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="dllA" publicKeyToken="blah" culture="neutral" />
    <codeBase version="blah" href="file:///C:/Original/Dir/dllA.dll" />
  </dependentAssembly>
</runtime>
Jesse
Why do you want to do this ?
Nix