We have a project with many dll files which get loaded when the application starts. The baseaddresses of the dll files do overlap so that the memory image gets relocated. Is there a possibility to assign the baseaddresses automatically or a way to calculate a "good" baseaddress for each dll file?
You can use the REBASE utility which ships with the platform SDK and with Visual studio I think to set the base addresses of a whole bunch of DLLS loaded by the appliction
You supply REBASE with a list of the DLLS that make up your program, not including system Dlls, it then performs a dummy load of all the DLLs and assigns them new base addresses.
This can be performed as part of a final build step.
There is a Dr Dobbs article on rebasing here and a Microsoft article on rebasing in general here
If you are distributing the DLLs, regardless how you set your base address, there is always a risk that other DLLs not written by you are loaded at that address already (for example global hooks DLLs).
Additionally if you are building for Vista you should actually use /DYNAMICBASE to enable ASLR to kick in.
Here is the msdn link: http://msdn.microsoft.com/en-us/library/bb384887.aspx.