Reputation: 11431
This question is regarding dynamic linking of libraries and usage of dynamic linking of libraries in application.
For example we are devloping an application using C++ using Visual studio environment.
Here for include header files we specify in Additional Include Directories, and in Additional Dependencies: Mylibrary.lib in Additional Libraries Directories: We specifies path of libraries
And in Windows we also have "LoadLibrary" API which is used to load dynamically linked ibrary.
My question is
Thanks!
Upvotes: 0
Views: 355
Reputation: 182
You asked that you can include dll in Additional dependencies libraries, and then why to use loadlibrary.
First lets clear the understanding:
While linking statically, A programmer is needed to add the .lib file to Additional library dependency, which is linked to the caller program at compile time,
However, Dlls are loaded dynamically, hence you need not to add dlls in Additional library dependency when you are using LoadLibrary ie; if you are linking the Dll explicitly you are not needed to give your dll path in Additional library dependencies.
Please note: using LoadLibrary you will be able to Get the Dll handle, which you can call the exported function using GetProcAddress.
refer: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx
Upvotes: 0
Reputation: 2305
Imagine that you have a software that for example needes at a determined time to convert Internet network address into strings. On windows vista or later you can use the "InetNtop" function that is also able to deal with ipv6, but if you link directly to the DLL your program will no work on lower OS (ex: windows xp). So the best solution would probably be making 2 DLL's one that used "InetNtop" and another that used for example "inet_ntoa". Then your "main" program would do at runtime a LoadLibrary of the "InetNtop DLL", or the "inet_ntoa DLL", according to the OS that he his installed.
Upvotes: 0
Reputation: 258548
LoadLibrary
lets you continue program execution if the dll is not on the running machine. It returns an error status that can be checked and execution can be continued.
Also, linking lets you do stuff like use classes from the other binary & others. LoadLibrary
only lets you find functions via GetProcAddress
.
Upvotes: 2