Dynamic link library between VC and Delphi
Delphi calls VC DLL
DLL Sound Name Format in VC: Extern "C" Void __Declspec (dllexport) __stdcall showmess (hwnd hwnd, char * mess); output format is: _showMess @ 8, "8" is the number of function parameter bytes to avoid name splitting, can be used The following method is resolved: 1. Do not add __stdcall in the declaration, use VC default format __cdecl, but in Delphi, you want to indicate the call format as CDECL. 2. Add a DEF file in the VC project, such as: library exports showmess @ 1 DLL output function name is not divided. Delphi Model: Procedure ShowMess (H: hwnd; mess: pchar); stdcall; {cdecl;} External libName; if there is no STDCALL or CDECL, Delphi Default Register (FastCall) call format. Note that Delphi is aligned with the VC, and use the following format when defined in the VC: #pragma pack (4) // Structure Definition #pragma pack () Common Tool:
TDUMP.EXE-DELPHI 4 and C Builder 3
Impdef.exe and Implib.exe - C Builder 3
DUMPBIN.EXE-VC5.0
LIB.EXE-VC5.0
VC call Delphi's DLL
Delphi's reputation format: function showdialog (hmainwnd: thandle; msg: pchar): Integer; stdcall; When you are in a DLL file, the name is not divided. Call format in VC:
EXTERN "C" __DECLSPEC (DLLIMPORT) INT __STDCALL Showdialog (HWND HWND, CHAR * MSG);
. If you have __stdcall, you will require the corresponding function name in the lib file to split, and you can have the following steps to generate a lib file:
. Generate a DEF file with impdef.exe, format is: IMPDEF DEF file name DLL file name
. Manual modulation DEF file parameters, such as ShowDialog change to showdialog @ 8
. Generate lib files with lib.exe, format: lib / def: DEF file name
. If there is no __stdcall in the name, the default call format is still stdcall, but the name split is not required, and the LIB file can be generated by the following batch file mklib.bat:
@echo off if% 1. ==. goto error impdef% 1.def% 1.dll lib /def :%1.def goto end: error echo usage: MKLIB DLLNAME Echo Note: don't add extension ".dll" To Parameter "Dllname": End