2

I have successfully divided a large MFC project into a couple of smaller DLL projects. Now I want to have a separate folder called "DLL" in my application's folder, where all the all the DLLs from the subprojects are placed.

Can anybody give me guidance in how to achieve this?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Why do you need to put the DLLs in a separate folder? Why can't you just include them in the same folder as the EXE? – Cody Gray - on strike Feb 28 '11 at 08:22
  • 2
    i have round about 200 dll files its so confusing when i open the application folder – santosh dhanawade Feb 28 '11 at 08:56
  • 1
    I wouldn't call 200 DLL files "a couple of smaller DLL projects". More importantly, the contents of the application folder shouldn't really be relevant. Rarely does the user interact directly with the application in the folder. They click on an icon or use the Start menu. If you have a well-designed installer, this shouldn't be an issue. – Cody Gray - on strike Feb 28 '11 at 09:05
  • you really not understand what i want to mention. as i have 200 dll files it so deficult to maintains such big project – santosh dhanawade Mar 01 '11 at 07:41
  • 1
    You can use a [Private Assembly Manifest to put dlls in a subdirectory](http://stackoverflow.com/a/36644602/321013). – Martin Ba Apr 15 '16 at 20:33

3 Answers3

4

If you use LoadLibrary, you simply have to explicitly specify the full path of the DLLs you load.

If the DLLs are implicitly linked, you can do this in two ways.

  • Have the installer modify the PATH variable. This is intrusive and "bad form"
  • Write a "loader" application that locally modifies the path variable, then executes the real executable.

The best solution would be to simply put the DLLs in the same directory as the executable.

Erik
  • 88,732
  • 13
  • 198
  • 189
4

DLL redirection is a fairly new feature (Windows 2000 IIRC). Name your DLL directory <myapp>.exe.local, and Windows will check it first for anything loaded via LoadLibrary(Ex). This includes delay-loaded DLLs.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • 1
    For more information about that type of redirection, see [this article](http://blogs.msdn.com/b/junfeng/archive/2006/01/24/517221.aspx). – Cody Gray - on strike Feb 28 '11 at 10:14
  • Good link. So the directory form is XP, not 2000. – MSalters Feb 28 '11 at 10:23
  • Well, there was some support for `.local` in Windows 2000, but I don't remember exactly what. I think it may have been limited to COM components or something. But [side-by-side assemblies](http://msdn.microsoft.com/en-us/library/dd408052) weren't introduced until XP. – Cody Gray - on strike Feb 28 '11 at 10:48
-2

EDIT: As pointed out by Eric this doesn't work. Sorry.

See Dynamic-Link Library Search Order. In short you can do so using registry keys under the "HKEY_LOCAL_MACHINE\SORTWARE\Microsoft\Windows\CurrentVersion\App Paths" key. A reg file like the following shows how:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe]
@="C:\\Program Files\\MyCompany\\MyApp\\MyApp.exe"
"Path"="C:\\Program Files\\MyCompany\\MyApp\\MyDLLs"
Steve
  • 1,760
  • 10
  • 18
  • Where in the documentation that you link to is the use of that Registry key recommended? – Cody Gray - on strike Feb 28 '11 at 08:36
  • According to the page you link: "The App Paths key is not used when computing the DLL search path." – Erik Feb 28 '11 at 08:37
  • @Erik: Looks like you're right. The "Safe Search Order" (which is on by default on modern versions of windows) seems to break this technique. It used to work. I should have read my own links more carefully. – Steve Feb 28 '11 at 08:44
  • No, even if `SafeDllSearchMode` is disabled, the link says the same thing: "The App Paths key is not used when computing the DLL search path." – Cody Gray - on strike Feb 28 '11 at 08:44
  • HI Steve. In fact, you can do this: http://stackoverflow.com/a/36644602/321013 ... I used to think for years it isn't possible too, but it just works. – Martin Ba Apr 15 '16 at 20:34