简体   繁体   中英

Use functions in a DLL without loading it?

I am looking at some c++/c code, the open source ovaldi project. I see that they include pcre.dll in the distribution and are making calls to functions in that library in the code; but they never load the dll; they just include the pcre.h header and seem to have access to the functions. Are they really just building with a static library and distributing pcre.dll on accident or is there a way to do this?

What do you mean they don't load the DLL? Not calling LoadLibrary ? Probably are using an import table, the OS loader will load the DLL automatically.

They DO load the dll, but just implicitly. You see, you can create a .lib file which is responsible for loading the dll and redirecting calls, link to the lib, include the header and that's it. In Visual Studio this is done automatically, when you set a dependency to a dll project

The application itself can be built with linker indications to automatically find and load the DLL without needing to do so explicitly. True dynamic loading of DLLs is usually only needed when the question is which version of a DLL to load.

You can load dynamic libraries at startup, but then you're required to restart the program to reload the library if the library changes. Loading the library during runtime with LoadLibrary or dlopen (unix) allows you to update a dynamic library while the process is running. This is good for long running processes such as a server, but it also incurs extra overhead for reloading the library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM