Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Marshal.Copy Struct -> ushort[]

Status
Not open for further replies.

Erakis

Programmer
Jan 10, 2003
26
CA
Hi,

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top