This code demonstrates one method to rebase DLL's on both Windows 9X and NT platforms to prevent base address collisions.
The method used in NiftyLoad is very simple, and probably prone to a number of flaws. The NiftyLoadLibrary function first loades the library using the LoadLibrary API. It then checks to see if the dll was successfully loaded at its normal base address. If the Dll's base address is the load address the function returns the HINSTANCE of the DLL and the calling application proceeds normally. If the base and load address are detected to be diffrent, then the dll is unloaded, and a memory mapped file is created. NiftyLoadLibrary reads the dll into the memory mapped file and performs the fixups required if the dll was loaded at the memory mapped sections base address. The complete image is then written to the DLL, the memory section is closed and LoadLibrary is again called to load the address. If everything went to plan, the dll should now load at the address previously occupied by the memory section without any relocation fixups being performed by the OS.
See the PlatformSDK documentation for ReBaseImage for more information.
The current version of NiftyLoadLibrary suffers from a number of flaws: