Monday, April 5, 2010

What is DLL Dynamic Link Library

A DLL is a Dynamic Link Library
In a nut shell, a dynamic link library (DLL) is a collection of small programs, which can be called upon when needed by the executable program (EXE) that is running. The DLL lets the executable communicate with a specific device such as a printer or may contain source code to do particular functions.

An example would be if the program (exe) needs to get the free space of your hard drive. It can call the DLL file that contains the function with parameters and a call function. The DLL will then tell the executable the free space. This allows the executable to be smaller in size and not have to write the function that has already exists.

This allows any program the information about the free space, without having to write all the source code and it saves space on your hard drive as well. When a DLL is used in this fashion are also known as shared files.

The advantage of DLL files is that, because they do not get loaded into random access memory (RAM) together with the main program, space is saved in RAM. When and if a DLL file is called, then it is loaded. For example, you are editing a Microsoft Word document, the printer DLL file does not need to be loaded into RAM. If you decide to print the document, then the printer DLL file is loaded and a call is made to print.

All in all a DLL is an executable file that cannot run on its own, it can only run from inside an executable file. This would be like having a car without an engine, where as an executable has an engine.

To do load a DLLl file, an executable needs to declare the DLL function. A DLL may have many different functions in it. Then when needed the call is made with the required parameters.

Here is what a Declaration and call might look like in a executable file. This example is simplified so that you might understand it better:

Declare GetFreeSpacex, Kernel32.dll (Drive_Letter, Buffers_If_Any, Value_Returned)
Now lets run a program and make the call.
The DLL is not loaded into RAM until the next line.
GetFreeSpacex "C",Buffers_If_Any, Drive_Letter
Now let's tell the user how much free space is on drive C
Use a MessageBox = "The free space on drive C: is ", Value_Returned, "bytes"
This call required 3 lines of code. Where as if you did not call the DLL file it may have taken you 30 or 40 lines of code.
If a call or a declaration is made incorrectly a GPF (General Protection Fault) may occur. A call to the same DLL but of a different version might require more or less parameters; or the call may not exist. If a DLL or an executable is the wrong version for your OS (Operating System) it will cause a GPF or lockup your machine. To fix GPF errors you should use a tool like System Sentry. System Sentry can show you what calls are available in a DLL file and what Calls an executable file is making. It can also tell what version a DLL is, and track when one is replaced.

Generally newer version DLL files are backward compatiable.DLL files from Windows ME may not be compatible with Windows 98. Many Windows ME files work well on 98 but not all will. The same hold true for Windows XP and 2003. If you dual boot a computer with XP and 2003 you must use the file C:\NTLDR and C:\ from Windows 2003. If you use the files from XP Windows 2003 will not boot, but XP will. NTLDR is backward compatible.

No comments:

Post a Comment