Forcing static loading of dll from given directory
In our application, we dynamically load a dll file, which again has static bindings to other dlls.
Until now, all this dlls have been in our application folder. From now on, we want to move these dlls into a directory structure. Which folder the dll should be loaded from is to be decided at runtime. (versioning / dynamic updates...)
Question 1: What is the best way of forcing the dynamically loaded library to look for static loaded libraries in a given folder?
Question 2: How can we prevent that it loads the static libr开发者_如何学Caries from the application folder if a older version of the libraries is left behind there?
(btw, it's a win32 application...)
For Q1 you should be looking into SetDllDirectory
. It affects all subsequent DLL searches, with the proviso that DLLs in the application folder (such as your old DLLs) still take precedence.
Question 2 is then immediately answered: if you don't want that, don't use implicit DLL loading. Use LoadLibraryEx
, and use a full path. That's the only way to prevent Windows from searching.
精彩评论