How are .dll files used??

Hello. I would like to know how to use a .dll in my program and what exactly a
.dll does. If anyone can answer my question, please do.


That's about it, thanks.

Note: Please explain in simple terms, I get confused very easily when you use c++ pro terms.
Last edited on
libraries (dynamic or not) can be 'anything' (data or executable code and more). I have seen dlls that are just piles of images or icons. But the most used format is executable code.
they work like this ... the dll has the executable binary machine code for a routine (or a full blown object, including its routines, whatever) and the linker has the main program load the dll into memory and jump to the correct offset, run the routine, and pop back to the main program memory area.

to do that you generally have a .h file in your code (so you have function headers and such to tell you what parameters etc are) and a .lib file (this may be optional, I forget) may be there to help the compiler and linker put it together, and a .dll file that just needs to exist in the path when the program is running. Calling the functions from the .h file should work when you compile and run the code. At least in visual studio, simply adding the .h and the .lib (if any) to the project and having the .dll file in the path/scope is all you need to do to call the functions in the .h file.

later, you can change the .dll file and run the program with the updated code and it will still work, if the dll interfaces are the same. This is a good way to update programs with smaller files rather than resend everything every time you need to update.

try a simple one; there are many simple to use examples on the web, eg the zlib compression library can be had in a dll and its pretty easy to use.
Last edited on
A DLL (dynamic link library) is a way to reduce the memory usage on a computer. It can let a program load new features after the program was created, but I think that's a lesser used aspect.

Consider a windows program. It uses a bunch of code to draw windows, move windows, minimze and maximize windows, etc. A lot of this code is in a library. With "static linking", a copy of the library code gets put into the windows program.

Now consider that there might be 2 windows programs, or 20, or 4,000. They all use that windows library to some extent or another and if they all have their own copy of the code, then each program is bigger than it needs to be. Also, because it's bigger, it takes longer to load and takes up more RAM. Yuck. How can we fix this?

What if we allowed each program to share a copy of the library code? The operating system could "load" the library (read it from disk into RAM) "dynamically" (whenever it's needed). That is the essence of a DLL. It's a library of shared code that gets loaded when needed. It can also be unloaded when it's no longer needed.

Hope this helps. My background is UNIX so some of what I've said might not apply right to windows. I'm sure others will correct me.
So, I just put a DLL in the path of my program and it'll do whatever the .DLL does?

I'm very new to c++, a month or so into it, so please correct me if I'm wrong.
So, I just put a DLL in the path of my program and it'll do whatever the .DLL does?
No. You must write a program that calls a function in the DLL and then you have to "link" the program with the DLL.
Is this related to the 3DS homebrew question? You won't be able to use DLLs on 3DS, or at least not Windows ones.
Is this related to the 3DS homebrew question?

No, of course not.

Nobody answered that, why would I make another one unless
I thought I'd get an answer.

You won't be able to use DLLs on 3DS


I know.
Just checking. Some people do make separate threads for related questions, you know?
Yeah, I see that.
closed account (D4Ev4iN6)
I don't know what kind of project you're doing, but usually, if you want to use
a pre-existing library from, say, an SDK (Structured Development Kit) it will have the .h files (headers) in there. You then add the SDK to your include path and use the functions.

Depending on the SDK, they will sometimes add the 'extern __declspec(dllimport)' tag for you (this means you want to use an external function from a DLL).

Check out this example from the Microsoft docs. It shows a simple DLL internally, and a simple application that uses the DLL:

https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019

Topic archived. No new replies allowed.