Passing parameters from managed to unmanaged code

I need to use a method from a library that has the following signature in the header file:

NKREMOTELIB_API int __stdcall GetEvfFrame(
    const unsigned char*& buffer,
    size_t& size,
    NKRemoteEvfDisplayInfo& displayInfo);

I call them from C # using the following:

[DllImport("NKRemoteLib.dll")]
public static extern int GetEvfFrame(out IntPtr buffer, out IntPtr size, out NKRemoteEvfDisplayInfo displayInfo);

private void Test() {
    IntPtr size = new IntPtr();
    IntPtr buffer = new IntPtr();
    NKRemoteEvfDisplayInfo displayInfo;
    int res = GetEvfFrame(out buffer, out size, out displayInfo);
}

I have displayInfo defined as a struct in C #.

In my question, what is the meaning for the ampersand in the function signature in the header file? Why size_t & instead of size_t or char * & instead of char *?

+3
source share
3 answers

This has nothing to do with C ++ / C # interop. This is actually about C ++.

++ . , , . , . # out ref.

:

void f(int i)
{
    i = 5; 
}
void g(int &i)
{
    i = 5;
}

int i = 0, j = 0;
f(i);
g(j);
std::cout << i; // should print 0
std::cout << j; // should print 5

"", , , , , , , . , " " C- .

+1

pass-by-reference. , GetEvfFrame size_t, size_t.

p/invoke ref, out.

+1

(&) "". , # out.

0

All Articles