2

I'm making a wrapper for a C library. There is a method that changes 2 ints by the user giving 2 int pointers to the method. So if I have void changenums(int* a, int* b) what is a safe way to access this method in c#?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
user2348979
  • 143
  • 1
  • 2
  • 8

1 Answers1

4

Declare the p/invoke like this:

[DllImport(@"mydll.dll")]
static extern void changenums(ref int a, ref int b);

And call it like this:

int a = 0;
int b = 0;
changenums(ref a, ref b);
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490