Answer the question
In order to leave comments, you need to log in
Which is better to use #include or LoadLibrary?
Good day :)
I searched on the Internet, nothing particularly clear is written.
Answer the question
In order to leave comments, you need to log in
The question, in fact, is not a choice between LoadLibrary
and #include
, but a choice between explicit and implicit binding .
With implicit linking, the linker adds an additional import block for the specified library to the PE import section. This block is processed by the PE loader in preparation for starting the process. This information should already be familiar to you . By the time control passes to the process entry point, all implicitly linked libraries are already loaded and ready to go. The process code does not need to explicitly manage the loading of such libraries.
Explicit binding is performed entirely by the process code, for which a set of functions is usedto work with libraries. Explicit binding is a big chore. But sometimes without this routine in any way.
Search for dynamic libraries when running LoadLibrary
[ ? ] is carried out in accordance with a certain order . At the same time, dynamic library search paths can be managed manually by adding new ones or replacing existing search paths.
The preprocessor directive #include
[ ? ] is only indirectly related to the question. Actually the directive #pragma comment( lib )
[ ? ].
The pragma only works for the cl compiler from Microsoft. The static library connected in this way must be in the listed Library Path, in the project build settings. This pragma is an alternative to specifying a static library directly in a project's build settings.
This directive is often used in third-party headers, the code for which is supplied only in binary form, in static or dynamic libraries. Together with the dynamic library of such a solution, a static library is also supplied, which contains instructions for implicit linking with the dynamic library. The result of working #pragma comment( lib )
with such a static library will be the implicit linking of your code with the specified dynamic library.
The size of PE grows significantly when linked from static libraries.
Explicit and implicit binding have little effect on the size of the PE, but explicit binding makes life difficult for the developer, because the developer will have to support the loading of the library interface himself.
#include is a compiler preprocessor directive, it "fires" when you compile your source code.
LoadLibrary is a windows api function that loads a DLL. Accordingly, it "works" when the already compiled executable is launched. DLL is already compiled library - it should be somewhere on PATH.
2) As far as I know - no (what's in 8,10,2016 - xs, I've been on Linux for a long time)
3) I didn't understand at all, sorry
4) Once again - #include is not a "library", although of course it you can bubble the whole code, but imho it's better not to do that. ANNOUNCEMENTS should live in the includes, but the code itself in .cpp
5) again did not understand.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question