Archive for the 'DLLs' Category

A History of DLLs

Friday, May 4th, 2007

Dynamic link libraries (DLLs) have been a curse of the Windows operating system for quite some time, dating back to Windows 3.1. Before dynamic libraries existed, programmers reused previous code by statically linking it to their application. Basically, they would copy the code to each application as they compiled it from the source. If the static libraries were changed, the application would have to be re-compiled to take advantage of the new features.

Dynamic libraries were first used in the Multics operating system in 1964. Instead of loading code at compile-time (when the code is turned into computer instructions), dynamic libraries could be loaded right before the program itself was loaded (at load-time) or only when the program requested the library (at run-time). Dynamic linking makes code reuse much simpler, as it is not necessary to re-compile an application every time the library is changed in order to take advantage of bug fixes or performance enhancements. New applications can take advantage of new features, while the library itself remains compatible with older applications. Another way to use dynamic libraries is the “plug-in” method, where there is a generic interface that can be used by multiple programs (such as skins and visualizations for media players).

Dynamic linking also saves space on the hard disk and in memory, since one library can be linked by multiple programs at a time, depending on how the operating system’s object loader works. For example, the Linux dynamic library loader is “position-independent”, meaning that it can truly load one copy of the shared library into memory for all programs to use. Windows on the other hand is position-dependent – if multiple programs use conflicting memory addresses, then copies of the DLL must be loaded.

System DLLs in pre-Windows 2000 operating systems could be overwritten by any software vendor that felt like doing it (usually because the Windows DLLs were buggy), and this practice spawned the famous DLL-hell of Windows 9x operating systems. In Windows 2000 and XP, this practice has been limited, but system DLLs can still be overwritten temporarily, and non-system DLLs can still be easily overwritten whether they are important or not.

Shared DLLs are sometimes overwritten by different applications, causing other applications to stop working correctly, or an application may be expecting a specific version of a DLL that has been upgraded (or simply isn’t a standard part of the Windows installation). However, Windows 2000 and onward allow vendors the choice of placing their custom DLLs in the application’s folder, which will ensure the right one gets loaded.

While the problem has lessened, computers are finally outpacing software in terms of processing speed, hard disk space and memory. We have almost come full circle with libraries like Microsoft’s .NET allowing for multiple versions of the same library to co-exist side by side and allowing applications to be copied from one place to another without the need to register DLLs. In short, .NET is Microsoft’s long awaited answer to DLL hell, although its overall use (even by Microsoft) is still fairly limited. Windows Vista, which was promised to run on mostly on .NET-based code, has shipped with only 4% of the libraries compiled as .NET (sometimes referred to as “managed”) code.

So while things are improving, DLLs will be with us for some time in the Windows world. Eventually I suppose we’ll get back to statically linked libraries that will once again allow clean installation and un-installation of applications, and undoubtedly, someone will discover that by sharing these code libraries we can save memory and disk space…

Hot DLL Errors and their remedies

Tuesday, May 1st, 2007

Illegal System DLL Relocation in User32.dll or Shell32.dll

A couple of the latest Microsoft security patches have wreaked havoc on a few obscure and some not-so-obscure programs. After an installation of MS07-008 (KB928843) or MS07-017 (KB925902), certain programs may crash with the following error:

“app name” – illegal System DLL Relocation

One resolution is to download another patch from Microsoft, which fixes the problems. The patch can be downloaded from Microsoft Update [http://update.microsoft.com/microsoftupdate] or from [http://www.microsoft.com/downloads/details.aspx?familyid=74AD4188-3131-429C-8FCB-F7B3B0FD3D86&displaylang=en]. In some cases, upgrading the affected software will also fix the problem. Microsoft has listed the following programs known to have problems:

  • RealTek HD Audio Control Panel, versions 1.41, 1.45, 1.49, 1.57
  • ElsterFormular 2006 and 2007
  • TUGZip 3.4
  • CD-Tag 2.27
  • BMC PATROL 7.1

Additionally, Microsoft’s Security Response team has identified two more programs that are affected that are not mentioned in the Microsoft Knowledge Base (KB) article:

  • CrystalXP’s BricoPack Vista Inspirat 1.1
  • Grisoft Inc.’s AVG 7.5

Corrupt or Missing HAL.dll

The HAL.dll file contains the core libraries for Windows’ Hardware Abstraction Layer, which acts as a buffer between Windows applications and the computer hardware. There are many possible causes of HAL.dll corruption ranging from a botched dual-boot install to disk failure. Typically one of the following errors will appear regarding HAL.dll:

Windows could not start because the following file is missing or corrupt:
C:\WINDOWS\system32\hal.dll.
Please re-install a copy of the above file.

C:\WINDOWS\System32\Hal.dll missing or corrupt:
Please re-install a copy of the above file.

Cannot find C:\Windows\System32\hal.dll

Cannot find hal.dll

There are several solutions to the problem. First, restarting the computer may fix the problem. Secondly, the boot.ini file may be corrupt and need to be fixed. Check out the boot.ini by running msconfig (Start > Run… > msconfig). In the BOOT.INI section, click on the “Check All Boot Paths” button to make sure all boot paths lead to actual partitions. MSConfig will give you the option of removing the entry, but to fix the entry it will have to be edited manually.

If that does not solve the problem, it may be necessary to load the original HAL.dll file from the Windows installation CD. Boot to the CD and run the recovery console. At the console use the following commands to restore the HAL.dll file:

> attrib –H –R –S C:\boot.ini
> del c:\boot.ini
> bootcfg /rebuild
> fixboot

If that fails, boot to the recovery console again and try the following command:

> expand d:\i386\hal.dl_ c:\windows\system32\hal.dll

where ‘d:’ is the CD-ROM drive the Windows CD is in. If that fails, a “repair” installation of XP may solve the problem. The last ditch solution, assuming the hard drive has not been corrupted, is a fresh install of Windows XP, preferably on a separate partition or drive. Installing on the same partition as the existing Windows installation is dangerous because it will overwrite the “Program Files” directory (the Documents and Settings directory should be safe), which can cause all sorts of problems. It may still allow you to recover your data, however, and should be done if no other options remain.

NTDLL.dll errors

NTDLL.dll is a core Windows DLL that may become corrupted. There are myriad causes for this from spyware to sloppily written applications to sloppily written Windows Updates. Since this is a core DLL, the same steps for HAL.dll may work for NTDLL.dll as well. However, if booting is still an option, a registry cleaner may be a better cure than replacing the DLL in terms of time spent troubleshooting. An hour spent cleaning spyware and fixing the registry may save several hours in recovery consoles, moving data, reinstalling applications and restoring preferences.