I have a Delphi function exported from a DLL, and I'm trying to call it from C# without much luck.
The Delphi function looks like this:
procedure RunMe(text: PWideChar; doc: PWideChar; out resultOne: PWideChar; out resultTwo: PWideChar; out errorText: PWideChar; out warningText: PWideChar); stdcall;
In C# I import the function like this:
[DllImport("delphiLibrary.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern void RunMe(string text, string doc,
out string resultOne, out string resultTwo, out string errorText, out string warningText);
And then call it like this:
var text = "some text";
var doc = "some doc";
RunMe(text, doc, out string resultOne, out string resultTwo, out string errorText, out string warningText);
The error I get is of type System.Runtime.InteropServices.SEHException
with message external component has thrown an exception
My guess is something in the function signature is handled wrong, but my adventures on Google/StackOverflow have not led me to any clear answer.
Is PWideChar
not a string? I tried various mutations of the solution above, but I'm short of ideas by now.
Update: Differs from Calling a Delphi DLL from a C# .NET application since I don't have the possibility to modify the Delphi-code to use string buffers.
Update2: I don't have the possibility to modify the Delphi code.