2

I have a C++ API prototype

void Func(int& size);

How can I translate it to P/Invoke in C#?

From what I know, if I use

public static extern Func(ref int size); 

, the function will receive a pointer to the int instead of the value.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228

1 Answers1

5

(Ooops... meant this as an answer, not a comment).

And when you call it from C++, the function will receive a pointer also. How else do you think references are implemented? Func() will treat that pointer as a reference, so how it gets there isn't important.

James Curran
  • 101,701
  • 37
  • 181
  • 258