The ReBaseImage function is used to change the load address for the specified image, which reduces the required load time for a DLL.
Alternatively, you can use the Rebase tool.
BOOL ReBaseImage(
IN LPSTR CurrentImageName,
IN LPSTR SymbolPath,
IN BOOL fReBase,
IN BOOL fRebaseSysfileOk,
IN BOOL fGoingDown,
IN DWORD CheckImageSize,
OUT LPDWORD OldImageSize,
OUT LPDWORD OldImageBase,
OUT LPDWORD NewImageSize,
IN OUT LPDWORD NewImageBase,
IN DWORD TimeStamp
);
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError.
The ReBaseImage function changes the desired load address for the specified image. This operation involves reading the entire image and updating all fixups, debug information, checksum, and time stamp values. You can rebase an image to reduce the required load time for its DLLs. If an application can rely on a DLL being loaded at the desired load address, then the system loader does not have to relocate the image. The image is simply loaded into the application's virtual address space and the DllMain function is called, if one is present.
A well-behaved application has its DLLs rebased so they each fall within a unique range of the virtual address space. The system DLLs are currently based in memory from 0x70000000 to 0x78000000 (0x68000000 to 0x78000000 on MIPS). Therefore, you should base your DLLs from 0x60000000 to 0x68000000. One possible scheme is to choose a base address based on the first letter of the DLL name, as shown in the following table.
First Letter | Base Address |
---|---|
A - C | 0x60000000 |
D - F | 0x61000000 |
G - I | 0x62000000 |
J - L | 0x63000000 |
M - O | 0x64000000 |
P - R | 0x65000000 |
S - U | 0x66000000 |
V - X | 0x67000000 |
Y - Z | 0x68000000 |
By using these suggestions with the ReBaseImage function, each DLL in an application can be assigned a unique base address. This process can be part of the build process or part of the final release procedure for the application.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Windows CE: Unsupported.
Header: Declared in imagehlp.h.
Import Library: Use imagehlp.lib.
PE Image Helper (ImageHlp) Overview, ImageHlp Image Modification Functions, DllMain