Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Im not quite understanding about .dll file ? why do we need to use it?
Posted

To break your program up into smaller, more manageable chunks that can be used by more than one application.

If you write your application as one EXE file, then firsth it will be a single huge file, and secondly, none of the code in the file can be used in your next app without physically copying the code source from one to the other.

Suppose you write a really useful class form handling your main company database. It's wonderful - so in your next app, you want to use it again. You copy the code, and slap it into the new project. Fine - it all works. You do it again, and again. But then someone finds a problem in the second app - and it needs a change in your wonder class to fix it. What do you do? Do you change just the copy in the second app? Or do you update all the other apps individually? What if there is a different problem in the third app which needs a different change? Suddenly, you are faced with 10 or twelve different and incompatible versions of the same code - and it all starts to be a nightmare.

If instead, you put your class in a separate DLL, all the others could refer to it. And provided that your changes for app 2 don't impact on the functionality exposed for the others, it all works. You have a single set of code, which all the others automatically use and effectively get updated to the latest version of, without any work, or configuration hassle, or anything!

Keeping everything in a single exe is fine, up to a point, but it's a bit like the early history of cars: every manufacturer had their own idea of what controls you need to use to drive a car, and where they should be placed. Slowly, they all moved to use a common set of controls: a wheel and three pedals in a defined order.
Can you imagine what fun it would be to hire a car if it had three hand levers and a foot controlled steering bar?

That's because they considered each car as a separate unit (a single EXE) instead of using common features (in DLL files).
 
Share this answer
 
Comments
ProEnggSoft 17-Mar-12 6:21am    
Nicely explained. 5!
longchandara 17-Mar-12 11:44am    
so normally we create a dll file it similar to create a normal application. forexample app in vb.net, just dll file can import to another app for vb.net right?
OriginalGriff 17-Mar-12 11:55am    
Or C#, or C++ etc. yes.
The difference is that a DLL cannot run on it's own - it needs to be accessed by an EXE file.
longchandara 17-Mar-12 22:31pm    
thank you :)
DLL file concept enables easy integration of third party libraries in an application.

For example, if we want a TV, we purchase it and see the guide for the instructions on how to use it. Then using those instructions we operate the TV and our purpose is served, without knowing how the TV functions, what are the internal components, how they interact with each other etc.

Similarly, for a defined set of functionality, say, we want a nice chart to be incorporated in our application, but do not have enough idea and expertise or time to write a chart application.

In such case a good third party library can be taken either open source, freeware or commercial, then by reading the documentation on how to use the library, we can incorporate the charts in our application, without even knowing how the chart is drawn internally.

We are only concerned with the public methods, properties and events exposed by the library. This is easily facilitated by DLL files.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900