4

I have a dll which accepts a struct that contains a pointer to a function to do a callback.

How can I get an IntPtr to a function of my application to build the struct?

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class OPERATION {
        public uint OperationID;
        public IntPtr Context;  
        public IntPtr Callback; -> How to pass this?
    }

Here is the delegate accepting the OPERATION struct

public delegate void MY_CALLBACK([In] OPERATION operation, [In] uint msgId, [In] IntPtr msgDataPtr);
Sergi
  • 85
  • 1
  • 4

2 Answers2

6

use Marshal.GetFunctionPointerForDelegate

E-rich
  • 9,243
  • 11
  • 48
  • 79
John Knoeller
  • 33,512
  • 4
  • 61
  • 92
4

Maybe the Marshal.GetFunctionPointerForDelegate method may help you.

Konamiman
  • 49,681
  • 17
  • 108
  • 138