0

I am trying to understand dlls. But it is still a bit vague. So please forgive if this is a very stupid question.

Lets say I have a project with lots of files and a mainfile that #includes those files.

mainfile.cpp:

#include "fileA.h"
#include "fileB.h"
#include "fileC.h"

I can create a mydll.dll from this project. A lib is created along with that. (I used C++, VS)

Then I have a project UseMydll that uses this dll. There I include

#include "pch.h"
#include "fileA.h"
#include "fileB.h"
#include "fileC.h"

So whats the point then in creating the dll if I still need to include and provide my fileA,fileB,fileC ?

user3443063
  • 1,455
  • 4
  • 23
  • 37
  • 1
    Somewhat simplified, the DLL contains the *definitions* (implementation) of the functions in the library. The header files contains the *declarations* that the compiler needs to know about the functions in the library. – Some programmer dude Nov 07 '22 at 07:00
  • 2
    If I understand the situation, your DLL consists of lots of header files plus only one source file? And you are wondering why you still have to provide the headers files (but not the source file) when using the library? Your viewpoint might be skewed because a more typical DLL would encompass multiple source files. – JaMiT Nov 07 '22 at 07:10
  • 1
    Or in other (simplified, not formally correct) words, the header files tell the client of the lib (dll) what functions there are (in the lib/dll) what they are called and what their arguments are. So that the client code's linker can setup the correct calls – Pepijn Kramer Nov 07 '22 at 07:10
  • thanks some programmer dude. That made it clear for me !!! – user3443063 Nov 07 '22 at 07:14
  • 1
    Additionally, dynamic linkage can be achieved in a couple of ways. The lib file allows you to make a link-time dependency. Any program that links to your DLL this way will fail to run unless your DLL is there. A different way to do it is with load-time linkage. With this method, the DLL and any required function signatures are loaded manually. It can be more tricky to ensure you have the correct DLL version here, but there is no dependency on the lib, and the program will still run without the DLL present. In either case, you probably need to provide headers, as that is your interface. – paddy Nov 07 '22 at 07:15
  • 1
    Some details that might be useful: https://stackoverflow.com/a/35118400/4788546, https://stackoverflow.com/a/34777349/4788546, https://stackoverflow.com/a/32158521/4788546. – CristiFati Nov 08 '22 at 11:20

0 Answers0