If it is your own dll you can execute code in the initialization section.
Otherwise the dll needs to be fully loaded and then you can use trampolines to runtime patch any code.
"During loading" is not possible, because loading is not deterministic. What is possible is "during initialization" or "after loading".
- a dll can patch code during its initialization
or the other way around:
- you can only patch code in a dll after it is fully loaded. Because only then all addresses are resolved.