Passing C# byte array to unmanaged code  
Author Message
Gary Harper





PostPosted: Visual C# Language, Passing C# byte array to unmanaged code Top

This should be simple but I can't get it to work. I have C function:

BYTE _stdcall DrawFrame(short portAddress, unsigned char* pBuffer, int length, int pps)

How do I import it to C# and call it with a byte[]

I tried the following but it doesn't work:

[DllImport("inp.dll", EntryPoint = "DrawFrame")]

public static extern byte DrawFrame(short address, byte[] framePoints, int length, int pps);

Thanks,

Gary



Visual C#6  
 
 
Mattias Sjogren





PostPosted: Visual C# Language, Passing C# byte array to unmanaged code Top

Looks correct. In what way does it not work



 
 
Gary Harper





PostPosted: Visual C# Language, Passing C# byte array to unmanaged code Top

When I check the values inside the array on the C side they are not the same as on the C# side.  The values are always 1 on the C side for some reason!  Is there a special way I need to specify the byte[] parameter when I call the DrawFrame function within C#