Delphi calls VC's DLL
Extern “C” void __declspec(dllexport) __stdcall ShowMess(HWND hwnd, char* mess);
The output format is: _ShowMess@8, "8" is the number of bytes of function parameters
In order to avoid name splitting, the following methods can be used to solve the problem:
1. Do not add __stdcall in the statement and use the VC default format __cdecl. However, in Delphi, you must indicate that the calling format is cdecl.
2. Add def file in VC project, such as:
LIBRARY
EXPORTS
ShowMess@1
Then the output function name in the DLL is not split.
PRocedure ShowMess (h:HWND; mess:PChar); Stdcall;{Cdecl;} external LibName;
If there is no Stdcall or Cdecl statement, Delphi defaults to the Register(FastCall) calling format.
#pragma pack(4)
//structure definition
#pragma pack()
TDump.exe - provided by Delphi 4 and C++ Builder 3
Impdef.exe and Implib.exe - provided by C++ Builder 3
DumpBin.exe-provided by VC5.0
Lib.exe-provided by VC5.0
VC calls Delphi's DLL
Function ShowDialog( hMainWnd:THandle; Msg:PChar ):integer; stdcall;
Names are not split when outputting to a Dll file.
extern "C" __declspec(dllimport) int __stdcall ShowDialog( HWND hwnd,char* Msg );
. If __stdcall is included, the corresponding function name in the Lib file is required to be split. The following steps can be used to generate the Lib file:
. Use Impdef.exe to generate a def file in the format: Impdef def file name dll file name
. Manually adjust def file parameters, such as changing ShowDialog to ShowDialog@8
. Use Lib.exe to generate lib files in the format: Lib /def:def file name
. If there is no __stdcall in the statement, the default calling format is still stdcall, but name splitting is not required. Use the following batch file MkLib.bat to generate a Lib file:
@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