Hi,
Here is a stuct that I have to fill using a dll function :
The function signature : (Standart for ModBus communication protocol)
I would like to use it like :
But how can I convert my struct to a ushort[] reference ? And after that, how can I convert my ushort[] to a InfoRegister struct ?
I can use the UNSAFE mode for technical reasons. So I hope Marshal can do the trick ?
Thanks for you help.
Here is a stuct that I have to fill using a dll function :
Code:
struct InfoRegister
{
public uint TargetIdBitField;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9) ]
public char[] Label;
public byte Mode;
public byte Index;
public byte CS;
}
The function signature : (Standart for ModBus communication protocol)
Code:
public MODBUS_ERROR ReadRegisters( ..., ushort[] pun16RegArray );
I would like to use it like :
Code:
InfoRegister ir = new InfoRegister();
ReadRegisters( ir );
But how can I convert my struct to a ushort[] reference ? And after that, how can I convert my ushort[] to a InfoRegister struct ?
I can use the UNSAFE mode for technical reasons. So I hope Marshal can do the trick ?
Thanks for you help.