Load a DLL from another directory at program start

后端 未结 6 1036
予麋鹿
予麋鹿 2021-02-03 11:43

My basic issue is this: my program (MyProgram.exe) has a dependency on a DLL from another program (OtherProgram), and I\'m trying to avoid repackaging a new DLL every time Other

6条回答
  •  终归单人心
    2021-02-03 12:35

    I have struggled with the same problem and also found a dead end with the suggested methods like LoadLibrary, SetDllDirectory, Qt's addLibraryPath and others. Regardless of what I tried, the problem still remained that the application checked the libraries (and didn't find them) before actually running the code, so any code solution was bound to fail.

    I almost got desperate, but then discovered an extremely easy approach which might also be helpful in cases like yours: Use a batch file! (or a similar loader before the actual application)

    A Windows batch file for such a purpose could look like this:

    @echo off
    PATH=%PATH%;
    
    

    /edit: Just saw @SirDarius comment in Luchian's answer which describes that way, so just take my batch code bit as a reference and all credits go to him.

提交回复
热议问题