Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

c++ - Locate DLL path by giving a DLLName

If I do

LoadLibrary("MyTest.dll")

Windows will locate and load it from "C:TestFolderTestMyTest.dll", because "C:TestFolderTest" is in %PATH% folder.

How can I emulate same function? I need to locate C:TestFolderTestMyTest.dll (C:TestFolderTest 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...