Saturday, September 4, 2010

Dll, What is it?

Have you ever opened your System32 folder, if yes than you are aware of dll files because there are a lot of dll files in it. but like most of the people you also don't know what they are for? In this tutorial I have tried to explained the concept and use of DLL files. The complete article is based on the book Let Us C by Yashwant Kanetkar.

Let begin this article with the short story of DOS or we can say 16-bit environment. Back in those days when a program was written/developed the library function which are called from each program become part of executable file (.EXE) for that program. Thus the same function gets replicated in several EXE files, thereby wasting precious disk space/memory.

No Reuse
Thus there is no reuse of these library function. Consider this e.g. suppose there are 2 programs say P1 and P2, both these programs need a function or driver say video() when we build these two program to executable file the function video() got embedded in both these program, wasting the memory space. But if this function is already in OS and these 2 program just call it than this function will be reused, this what we are using now a days.

Look and Feel
DOS-based programs like WordStar, FoxPro etc offer different types of menus. This is because DOS/BIOS don't provide any function for creating user interface elements like menus. As the look and feel of all DOS based program are different, the user takes a lot of time in learning how to interact with the program.

Messy Programming and Calling mechanism
Also there was another problem from calling a function from a executable, i.e. these EXE's call's windows functions using Interrupts numbers and Registers, which are very difficult to remember. For e.g. if we are to position a cursor on the screen using a BIOS function we are required to remember the following details:

Interrupt number - 16
CPU Registers to be used:
AH - 2 (service number)
DH - Row number where cursor is to be positioned
DL - Column number where cursor is to be positioned

while using these interrupt numbers and errors there is always a chance of error

The new programming model which we are using today to create our programs is called Windows programming model, it is designed to eliminate all the problems that we face in DOS model.

Now instead of calling functions via Interrupts numbers and Registers, windows provides functions within itself which can be called using names. These functions are called API (Application programming Interface) functions.

Today almost all programs calls several API function during course of its execution. imagine how much disk space would have been wasted had each of these fictions become part of the EXE file of each program. To avoid this, the API function are stored in special files that have an extension .DLL.

DLL stands for Dynamic Link Library, it provides a library of functions. These functions can also be shared between several application running in windows. As a result the size of EXE files does not go out of hand.
Simple e.g. Every one here I suppose may be aware of Shell32.dll its a file in System32 folder, now this file apart from different API function contains some images too which we use like ICONS, most of the icons that we use in Windows are a part of Shell32.dll file. This helps reducing memory space.

I hope you got the concept, if not feel free to post your queries. And if someone knows here something more about DLL do contribute it here.

0 comments:

Post a Comment