Sign in to follow this  
loom91

When and why to use DLLs?

Recommended Posts

Well, that's pretty much it. When and why should I resort to importing functions and classes(and other mumbo-jumbos) from DLL files instead of good ol' headers? What's the use of those files that caused me so much headach? Any reasons why I shouldn't kick Microsoft hard in the *** :) Thanks. Molu

Share this post


Link to post
Share on other sites
I use them to seperate API-specific code from my main engine, so a new API could be used for a different platform or code can be updated by just using a new DLL. Its just another way of making your code more modulor.

You may not have a need for them if your project is on a smaller scale.

Share this post


Link to post
Share on other sites
I use dynamic linking (either dlls or shared objects under Unix) whenever I am designing a system with components I may want to "swap out" later.

For example, a custom email client I wrote a number of years ago featured a "pop3.dll", and an "smtp.dll" which were swappable implementations of the pop3 and smtp client interactions. I wrote them to be independant from the main executable in case there was a vulnerability or bug in the software. It turned out to be useful later when I located an issue in the pop3 implementation; rather than forcing a reinstall I sent out a patch which simply replaced the pop3 dll.

Other examples include writing a game engine which has swappable graphics interfaces, for example, a d3dcore.dll, and a glcore.dll reflecting the API used in each. I have also written my own version of "pluggable authentication" which was more of an experiment than anything, but still worked.

Share this post


Link to post
Share on other sites
DLL's can be used for alot of things, especially "plug-in ability".

The way I'm using DLL's in my pet project is to have a main app for registering what filetypes should generate thumbnails in windows explorer but the actual image extractors in different DLL's. This allows me to easily add new image extractors and as mentioned before, patch any bugs without the need to reinstall. The best part is that anyone can write a DLL and plug it in to the app.

Share this post


Link to post
Share on other sites
I use DLLs to house any complex window classes, engines or code that do not releate to a specicfc application (e.g My virtural file system will be housed in a dll.)

Also as others have said plugins. This is because each plugin DLL can be added and removed from the program without affectin the others.

Otherwise, all code must be included at compile time.

DLLs also allow you to code in C++ to extend languages like visual basic.

DLLs are for what you want them to be. When you want code that can be added to your program WITHOUT recompiling (eg by the user) or if you have a large amount of common code or systems. The code in the DLL can be shared by many programs taking up less memory. (The code is only loaded in one copy)

Share this post


Link to post
Share on other sites
If two programs need lots of the same functions then it obviously saves a lot of storage space if all the identical functions are stored in a library (i.e a DLL) and then you only need two small programs to call the functions in the DLL.
If you had to add enormous header files each time you wanted to write a program that used Windows type functions then each program would be enormous!

Also: if Windows changes some of its functions such as from Win98 to WinXP, your programs would not change but they would look different if the DLL is updated.

If you write windows programs you are already using functions from Windows DLLs but they are connected to your program automatically by your compiler/linker.

Share this post


Link to post
Share on other sites
Basically, most of the above arguments are not reasons to use DLLs, just to structure your program sensibly:

- Plug-ins can be done without DLLs, just write them to a given interface specification and staitc link with your main program
- If you have two or more programs which share a lot of code (Example: game and editor), consider putting them in the same .exe, and using commandline parameters to tell it which program to run.
- If you want to update your app, just drop a new .exe in
- In this day and age it is very unlikely that the new .exe will become a prohibitively large download, but just in case it does, use a binary patching system (which will regain more than not using .DLLs loses).
- Having DLLs won't help you do updates if you change the interface, as you then have to distribute the exe AND DLLs.

IMHO if you have code which is under the same level of control/ IP rights, there's no real point in storing it in more than one binary module - it's just complicated with no real gain.

If everyone who needs to build the executable is allowed to have access to the source, they may as well recompile that too.

In some OSs you need to make complicated changes to code to make it work properly with DLLs. Don't do it. Just don't use DLLs unless you ABSOLUTELY HAVE TO.

(Note for .NET users: .NET assemblies ARE NOT DLLs)

Mark

Share this post


Link to post
Share on other sites
Quote:
Original post by markr
Basically, most of the above arguments are not reasons to use DLLs, just to structure your program sensibly:


In what way? In the next part you explain ways to avoid using DLLs. Whlist these are all valid methords, why do you belive they are more valid than just using DLLs?

Quote:
- Plug-ins can be done without DLLs, just write them to a given interface specification and staitc link with your main program


In which case all plugins must be present at compile time, what about 3rd party plugins created for your application but at the user level? (You know, skins etc?)

Quote:
- If you have two or more programs which share a lot of code (Example: game and editor), consider putting them in the same .exe, and using commandline parameters to tell it which program to run.


Wha.....?

Do you really think thats better than using a DLL? I think your just trying to come up with ways round DLLs which, lets face it are longer and inefficant. You have too big apps that use some shared code. According to you we must put both thse apps and the shared code all under the same EXE. This way the image for both apps have to be loaded regardless of which one your using.



Quote:
- If you want to update your app, just drop a new .exe in


But no good if a third party wants to create a plug in and you dont want to share your EXE code with them.

Quote:
- Having DLLs won't help you do updates if you change the interface, as you then have to distribute the exe AND DLLs.


Not having DLLs wont help you either in such a case. So what have you lost by using DLLs?

Quote:
If everyone who needs to build the executable is allowed to have access to the source, they may as well recompile that too.


Well not with a 3rd part plugin system they dont.

[quote]In some OSs you need to make complicated changes to code to make it work properly with DLLs./quote]

This is the only legitimate reason so far. If you planning to write for non-win32 OSs then yeah, avoid DLLs. Otherwise use DLLs if approprate and you want to.

Share this post


Link to post
Share on other sites
When to use DLLs:
1) When you want your program to be moddable, or use plugins
why? So another user without the source code (or a user who dosn't want to rebuild the entire program just to add a plugin) may drop in a new set of functionality replacing (or simply adding, for plugins) the DLL you wrote.

2) When you want to reuse among multiple projects that DLL
why? Save hard drive space, possibly memory space if multiple projects run at the same time using that DLL.

3) When you want to be able to patch/upgrade over the net.
why? so users on lower speed connections decrease their download time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this