staafl

delegate callbacks to interop

Jul 28th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. class Demo
  5. {
  6. static int Add(int left, int right) {
  7. return left + right;
  8. }
  9. [DllImport("MyLibrary.dll")]
  10. static extern void Foo(Func<int, int, int> func, bool bar);
  11. ...
  12.  
  13. static void Main() {
  14. // call C++ with a delegate pointing to your method
  15. Foo(Add, true);
  16. }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment