Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locate DLL path by giving a DLLName

Tags:

c++

c

dll

winapi

If I do

LoadLibrary("MyTest.dll")

Windows will locate and load it from "C:\TestFolder\Test\MyTest.dll", because "C:\TestFolder\Test\" is in %PATH% folder.

How can I emulate same function? I need to locate 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 a function?

P.S. I can't do LoadLibrary and then GetModuleHandle and finding Path, sometimes this DLL could be malicious DLL and I can't load it. So I need to find PATH without having to load it.


1 Answers

To load the DLL without running any malicious code inside, use LoadLibraryEx with the DONT_RESOLVE_DLL_REFERENCES and LOAD_LIBRARY_AS_DATAFILE flags.

Then you can use GetModuleFileName.

You should also read about all the other flags, which allow you to perform all the various searches Windows is capable of.

like image 173
Ben Voigt Avatar answered Feb 01 '26 22:02

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!