views:

527

answers:

1

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.

+4  A: 

(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