1
votes

I am wondering if someone could check my c# dllimport declaration for a dll compiled with Delphi XE2. Calling this dll from a ISAPI wrapper dll works fine but I am having no luck calling it from a c# asp.net app.

The Delphi procedure is defined as:

procedure ExecuteService(const RequestJSON :PWideChar; out ResponseJSON :Pointer; out ResponseJSONSize :Integer; out ResponseContent :Pointer; out ResponseContentSize :Integer); stdcall;

and the c# declaration is:

 [DllImport("services.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
        public static extern void BIExecuteService(
            String requestJSON,
            out IntPtr reposnseJSON,
            out int reposnseJSONSize,
            out IntPtr reposnseContent,
            out int reposnseContentSize
        );

Sometimes it works but mostly it gives a System.AccessViolationException.

I have been trying to solve this for days, do the declarations look correct?

Edit: Attaching to the IISExpress process in Delphi XE2 the error seems to occur in clr.dll. Maybe my library is corrupting something but I have no idea how to find out where!

Thanks,

AJ

1
Problem liable to be in how you call the function. You didn't show that. Ideally, you would show both Delphi and C# calling code. As asked, the question is trivial to answer, and the answer is probably of no use to you. This is a classic example of the XY problem.David Heffernan

1 Answers

1
votes

Your p/invoke declaration is correct. Your problems lie elsewhere.