I had some problems with passing a string since PChar for Delphi built a DLL and resolved it thanks to Jens Mühlenhoff.
Now I have one more problem -
I made a successful call to the C # method when passing to a DLL if the Delphi declaration is a regular type procedure, but if the Delphi declaration is a method type procedure, I get the error message "Attempting to read or write protected memory".
I tried searching ...
Here is the Delphi declaration
TCallBack = procedure ( s : String) of object;stdcall;
Here is the C # code
[DllImport( "DLLTest.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "DLL_Test" )] public static extern void DLL_Test(IntPtr p, [MarshalAs(UnmanagedType.LPStr)] string Location, int AIntValue); public delegate void MethodCallBackEvent(string s); public event MethodCallBackEvent Info; public void GetInfo(string s) { MessageBox.Show("Info: " + s); }
used as
Info = GetInfo; //or Info = new MethodCallBackEvent(GetInfo); IntPtr p = Marshal.GetFunctionPointerForDelegate(Info); DLL_Test(p, "location message", 10);
source share