Assume that:
An EXE loads two DLL (dll1 and dll2, and uses implicit loading ). Both DLL and dll2 export a function at the same time:
Int add (int A, int B );
If the Add function is called in EXE, which DLL's add function will it call?
To verify this result, we wrote a test example. The two DLL (Win32 DLL) Names mydll1 and mydll2 respectively, and let them export the same add function, but add a print output during implementation, used to identify which DLL is called.
The final result is related to the Lib sequence in the project configuration. That is to say,If the order in [LINK] Object/library modules is mydll1.lib mydll2.lib (before mydll1 ),ProgramFunction implementation in mydll1 is called. On the contrary, if mydll2.libmydll1. Lib is configured in the project, the main program calls the function implementation in mydll2..
It seems reasonable to see the result. EXE finds a function call in the DLL. It will traverse the DLL loaded by itself for search. This should be the key to the sequence. Find the First Matching and execute the call. So, who is in front of and who is called.
In this case, another problem occurs. For large programs, it is often divided into several modules. For interface unification, the same function needs to be exported in the DLL. How can the main program call the corresponding functions in the module to be executed?
The simplest and most direct method is to use dynamic loading and getprocaddress after loadlibrary.