If your method expects a callback to take a pointer to some structure, you can pass a managed callback when specifying P / Invoke DllImports as follows:
private delegate void MyCallback(IntPtr par);
[DllImport("MyLibrary.dll")]
public static extern void SomeFunction(MyCallback callback);
You can then marshal IntPtrinto the appropriate structure inside your actual callback method.
[change]
To pass a parameter intby reference, the following delegate signature should work best:
private delegate void MyCallback(ref int par);
Groo source
share