Access Violation when passing WideString arguments to Delphi DLL
Original Reporter info from Mantis: PascalDragon @PascalDragon
-
Reporter name: Sven Barth
Original Reporter info from Mantis: PascalDragon @PascalDragon
- Reporter name: Sven Barth
Description:
I have a Delphi DLL that exports methods which use WideStrings as text parameters.
When I call the DLLs methods with a FPC program I get access violations after the methods return.
When I recompile the DLL with FPC the problems are gone.
Similiar errors happen when I run a Delphi program with a FPC DLL.
Additional information:
Attached is a sample program (DllTestMain.pas), which is once compiled with FPC 2.2.4 (FPCTestMain.exe) and once with Delphi 6 (DelphiTestMain.exe) and a test DLL (TestDll.pas), which is also compiled once with FPC (FPCDll.dll) and once with Delphi (DelphiDll.dll).
The DLL exports four methods:
function ValueString(aStr: WideString): WideString; stdcall;
function ConstString(const aStr: WideString): WideString; stdcall;
procedure VarString(var aStr: WideString); stdcall;
procedure OutString(out aStr: WideString); stdcall;
The program first loads FPCDll.dll and tests all four methods (in the order above) and repeats the same with DelphiDll.dll.
If the main application is compiled with FPC it fails after the By-Value call of the Delphi DLL (it prints that the Const call will happen and then nothing... dead).
If the main application is compiled with Delphi it runs all four methods with both DLLs, but runtime errors are reported at three points during the run with the FPC DLL.
Mantis conversion info:
- Mantis ID: 14308
- OS: Win32
- OS Build: XP SP3
- Platform: i386
- Version: 2.2.4
- Monitored by: » Vincent (Vincent Snijders)