It often floats in the rivers and lakes, and has to deal with DLL. Sometimes we need to use C ++ builder to write a DLL, and then get it in VC (for example, write a form with C ++ builder to encapsulate it into DLL ); sometimes it is necessary to use the DLL compiled by VC in C ++ Builder (for example, to get a product development kit, this package is a bunch of DLL written by VC ).
Unfortunately, since the Implementation Details of the editors of MS and Borland (codegear) are different, the DLL generated by them cannot be universally used, which brings a lot of trouble to the reality. The following describes how to solve this problem.
1. VC generates DLL and C ++ builder calls.
1. Use extern "c" to modify the DLL function exported by VC. For example, extern "C" _ declspec (dllexport) int afunc (int );
2. Use the implib tool of C ++ builder to generate the Lib file corresponding to the DLL. For example, implib-a xxx. Lib XXX. dll (note that the-a switch must be enabled for implib ). After the Lib file is generated, C ++ builder can use this lib file.
II. C ++ builder generates DLL and VC calls.
1. Use extern "c" to modify the DLL function exported by C ++ builder. For example, extern "C" _ declspec (dllexport) int afunc (int );
2. Use the impdef tool of C ++ builder to generate the def file corresponding to the DLL. For example, impdef XXX. Def XXX. dll.
3. Open the XXX. Def file in notepad and delete "_" before each function name "_". For example, the original def file is:
-
C/C ++ code
-
LIBRARY XXX.DLLEXPORTS ___CPPdebugHook @2 ; ___CPPdebugHook _aFunc @1 ; _aFunc
After deletion, it becomes:
-
C/C ++ code
-
LIBRARY XXX.DLLEXPORTS __CPPdebugHook @2 ; ___CPPdebugHook aFunc @1 ; _aFunc
4. Use the VC lib tool to generate the Lib File Based on the def File above. For example, lib/DEF: XXX. Def. After the Lib file is generated, VC can use the Lib file.
To sum up, when the DLL developed by the two tools is used with each other, the main problem is the problem of the Lib library, which can solve this problem.