The main two usage methods
The main two usage methods are Explicit Linking and Implicit Linking.
Let’s look at their main differences so that we don’t get confused in subsequent implementations.
Explicit Linking
- During runtime, loading DLL and obtaining function pointers are required before using functions from the library.
- The main steps include loading the DLL, obtaining function pointers, invoking functions, and releasing resources.
- Achieved using
LoadLibraryandGetProcAddressfunctions. - Suitable for cases requiring higher code flexibility, finer-grained control, and avoiding excessive dependencies.
- Suitable for developing flexible and highly configurable programs.
Implicit Linking
- During compile time, DLL-related information is embedded into the executable file, eliminating the need to explicitly load DLLs.
- The main steps include including relevant header files, adding the .lib file to the linker configuration, and automatically linking functions from the DLL during compilation.
- Implemented using
#pragma comment(lib, “YourLibrary.lib”)or adding the .lib file in project settings. - Suitable for cases requiring simplified development processes, improved development efficiency, and reduced developer workload.
- Suitable for faster development and lower requirements on code structure.
The simplest classification method is whether .lib files are used; .lib files are used in implicit linking, while they are not required in explicit linking.
