IntPtr does not contain an eigenvalue

I have my own method that should deliver an array of bytes to the .NET wrapper. The natove method looks like this:

__declspec(dllexport) int WaitForData(unsigned char* pBuffer)
{
    return GetData(pBuffer);
}

GetData allocates a memory area using malloc and copies some data into it (stream of bytes). This byte stream was received through a socket connection. The return value is the length of pBuffer.

This method must be called from .NET. The import declaration is as follows:

[DllImport("CommunicationProxy.dll")]
public static extern int WaitForData(IntPtr buffer);

[EDIT]

The P / Invoke Interop Assistant, who advises dasblinkenlight, translates the prototype into the following import signature:

public static extern  int WaitForData(System.IntPtr pBuffer)

The result is the same: ptr = 0 after calling the method.

[/ EDIT]

The method attribute is called, the result is retrieved:

IntPtr ptr = new IntPtr();
int length = Wrapper.WaitForData(ref ptr);

byte[] buffer = new byte[length];
for(int i = 0;i<length;i++)
{
    buffer[i] = System.Runtime.InteropServices.Marshal.ReadByte(ptr, i);
}
Wrapper.FreeMemory(ptr);

, ptr , varible pBuffer. ptr 0, Wrapper.WaitForData , pBuffer .

? ?

+3
1

" ",

__declspec(dllexport) int WaitForData(unsigned char** pBuffer)

( value)

*pBuffer = 'something'

- ( int/length )

btw, ( , ref)

+3

All Articles