Call problems when multiple DLL files export the same function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.