In C++ I have a struct:-
typedef struct
{
unsigned char ucSpeed;
unsigned long ulLength;
unsigned char ucBulkInPipe;
unsigned char ucBulkOutPipe;
unsigned char ucInterruptPipe;
}USB_DEVICE_INFO, *PUSB_DEVICE_INFO;
In header I have:-
_API BOOL _InitialiseDevice(PUSB_DEVICE_INFO pDevInfo);
in CPP file I have a function
_API BOOL _InitialiseDevice(PUSB_DEVICE_INFO pDevInfo)
In C# I have struct:-
[StructLayout(LayoutKind.Sequential , Pack = 8)]
public struct USB_DEVICE_INFO
{
public byte ucSpeed ;
[MarshalAs(UnmanagedType.U8)]
public long ulLength;
public byte ucBulkInPipe;
public byte ucBulkOutPipe;
public byte ucInterruptPipe;
}
And calling it like this:-
[[DllImport(@"32.dll")]
public static extern bool _InitialiseDevice(out PUSB_DEVICE_INFO pDevInfo);
if (_InitialiseDevice(out m_sDeviceInfo) == false)
There are no errors except that the struct in C# isn't filled as I expected. The struct is filled in c++ like:-
ucSpeed = 1
ulLength = 1
ucBulkInPipe = 130
ucBulkOutPipe = 2
ucInterruptPipe = 0
But in C# it looks like this:-
ucBulkInPipe = 0
ucBulkOutPipe = 0
ucInterruptPipe = 0
ucSpeed = 1
ulLength = 642
I'm assuming I'm not marshalling it correctly but not sure how to correct it