Say I have a dll named midd开发者_StackOverflow社区le.dll that is importing functions from runme.dll
I now have a replacement runmeDBG.dll that has all the same functions exported as runme.dll
Is there a way to use middle.dll but have it link to the functions exported from runmeDBG.dll instead of runme.dll?
I can change the code for middle.dll but do not know the name of the dll that will contain the functions to use when I build middle.dll.
(And all of this in the context of C/C++ and the Mingw toolset)
If you access all the functions in the DLL via use of GetProcAddress
then yes, you could switch out which module you use at run time. Just load the alternative module (see LoadLibrary
) and use its handle as the argument to GetProcAddress
.
You wouldn't want to use this for too may imports however, it would get very tedious!
I'm assuming middle.dll is not yours, and it links statically to runme.dll. No, there's no way to change dll name in case of static linkage; you can, however, rename the runmeDBG.dll to runme.dll and place it somewhere where dll loader will find it. Or use a manifest to point the executable straight to the specific path. It's not a requirement that runme.dll sits in at specific path, is it?
Just rename the replacement and put it in the same directory as your executable.
This question is old but I found it first in Google as I met a very similar issue and then I found a better solution elsewhere. Here's the solution I found that is explained in another thread: Delay Loading DLLs.
How do I rename a DLL but still allow the EXE to find it?
This technique can be useful if, for example, a DLL was designed to be linked statically (with classes in the interface) but you need to actually load it dynamically without changing its interface. You simply have to tell Windows to delay load the DLL and when it actually loads the DLL, Windows calls your preload hook and then you just return an Handle to a different DLL (which maybe have a different name) that have the same interface.
精彩评论