I've had some problems passing string as PChar to Delphi built DLL, and resolved it thanks to Jens Mühlenhoff.
Now I have another issue -
I've made successful callback of c# method when passed to DLL if the Delphi declaration is a regular type procedure, but if Delphi declaration is a method type procedure I get "Attempted to read or write protected memory" error.
I tried searching...
Here is Delphi declaration
TCallBack = procedure ( s : String) of object;stdcall;
Here is C# code
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);
Info = GetInfo; //or Info = new MethodCallBackEvent(GetInfo);
IntPtr p = Marshal.GetFunctionPointerForDelegate(Info);
DLL_Test(p, "location message", 10);