Does Windows have a built-in way of checking if a DLL is present and could be loaded with LoadLibrary, without actually calling LoadLibrary?
I want to check for the presence of DLL B, from within a function called during LoadLibrary for DLL A. Calling LoadLibrary from within a LoadLibrary call (nested LoadLibrary calls) can cause a process to hang, so I'm looking for a different way of check if another DLL is queued to load, or has already been loaded.
GetModuleHandle()
can check if a DLL is already loaded.
While you are not supposed to call LoadLibraryEx()
in DllMain()
, calling it with LOAD_LIBRARY_AS_DATAFILE
might be OK. If you do this, you have to chop off the bottom two bits in the handle, and manually check that the machine value in the PE header is the same as your process. I don't know if the datafile file search is guaranteed to be the same as the normal DLL file search algorithm.
If you want to make sure a normal LoadLibrary()
would work, you would have to check the imports, and before you know it, you have written your own DLL loader...