Find the DLL path by specifying the DLLName

If i do

LoadLibrary("MyTest.dll")

      

Windows will find and load it from "C:\TestFolder\Test\MyTest.dll"

because it "C:\TestFolder\Test\"

is in the folder %PATH%

.

How can I emulate the same function? I need to find C:\TestFolder\Test\MyTest.dll

( C:\TestFolder\Test\

is in %PATH%

) by passing MyTest.dll

as an argument to a function. Is there such an API? or function?

PS I cannot execute LoadLibrary and then GetModuleHandle and find the Path, sometimes this DLL can be a malicious DLL and I cannot load it. So I need to find PATH without loading it.

+3


source to share


1 answer


To load a DLL without malicious code inside, use LoadLibraryEx

with the DONT_RESOLVE_DLL_REFERENCES

and flags LOAD_LIBRARY_AS_DATAFILE

.

Then you can use GetModuleFileName

.



You should also read about all the other flags that allow you to do all the different searches that Windows is capable of.

+11


source







All Articles