Hi all
I have a Delphi 2.0 program that uses an external DLL. This DLL is declared as follows in the Delphi code:
Function SynthesizeForms
(lemma : PChar; withApp : integer; codeType : integer;
var outBuf : array of SynthFormSet; bufLength : integer) : integer;
stdcall; external 'fmsynth.dll';
and is called like that:
var
formsBuffer : array[0..299] of SynthFormSet;
synteesitudvorme, i, j, x_tyybinumber, x_variandinumber : integer;
lemma : array[0..29] of char;
...
synteesitudvorme := SynthesizeForms (lemma, 0, j, formsBuffer, 300);
I've been struggling with trying to define correct Rust declaration for this external function and eventually came along with this (where dynlyb
is a libloading
crate):
type SynthFn<'lib> = dynlib::Symbol<'lib, unsafe extern "stdcall" fn(dt::PChar, dt::Integer, dt::Integer, &mut [SynthFormSet], dt::Integer) -> dt::Integer>;
and is seems to work, at least the DLL function gets called, provides (more or less expected) values into the array and returns a count, as expected.
BUT
After I return from Rust fn that was calling this DLL function, I invariably always have this:
error: process didn't exit successfully: `<exe-name censored>` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
In the WinDbg, I can see some drop_in_place
calls before the exception, so I presume this is a function-leaving block that's dropping values from stack, but otherwise than that I have no clue what's going on
I seem to have exhausted whatever knowledge concerning x86 architecture/WinDbg I might have had, so in a total desperation I humbly summon the community.
Maybe there's something that I might have missed with the Symbol definition? Or is it due to (rather) long array of struct
-s being defined on stack (it does not seem to prevent Delphi code from working, though)
Or might I benefit from parsing thru IR representation (if I might have it somehow)
Anyway, any suggestion is more than welcome!