Loading dll from another folder

In my application, I need to use dll A that depends on another dll B. A.dll is in my application folder and B.dll is in a subfolder of the application folder.

What can I do so that A.dll can load B.dll from its present location I can not change the location of these dlls or their source code - I can only change the code of the application.

Any ideas



Answer this question

Loading dll from another folder

  • gabriel oliva

    Maybe you can work with runtime dynamic linking. LoadLibrary function can accept relative path when loading DLL too:



    HMODULE myModule = ::LoadLibrary("MyPath\\MyLibrary.DLL");
    if (myModule != NULL)
    {

    /* Code here..*/

    ::FreeLibrary(myModule);
    }



    Regards,

    -chris



  • QUANTMCVA

    Simply change the PATH environment variable for your process just befor loading the library A. You can restore it to the old value after LoadLibrary is done.

  • Loading dll from another folder