Home Passing method pointer from C# to Delphi DLL
Reply: 0

Passing method pointer from C# to Delphi DLL

user1246 Published in March 23, 2018, 10:36 pm

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);

used as

            Info = GetInfo; //or Info = new MethodCallBackEvent(GetInfo);
            IntPtr p = Marshal.GetFunctionPointerForDelegate(Info);

            DLL_Test(p, "location message", 10);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305815 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO