V
VMI
How can I convert the following C struct into a C# struct? The struct is
sent to an API function (written in C) as parameter, and the function fills
it with data. I tried to convert it and most of it works but the data in the
foot struct is not correct (I believe it's a conversion problem between C#
and C).
The class I created in C# (from the struct) is at the bottom.
typedef struct
{
char iadl1[50+1];
char ictyi[50+1];
char auto_zone_ind;
char retcc;
struct {
char a;
char b;
char c;
char d;
char rsvd3[6];
} foot;
} ZIP4_PARM;
*****************************
/* My struct converted */
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class ZIP4_PARM
{
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=51 )]
public string iadl1;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=51 )]
public string ictyi;
public char auto_zone_ind;
public char retcc;
public footer foot;
public struct footer
{
public char a;
public char b;
public char c;
public char d;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=6)]
public string rsvd3;
}
}
sent to an API function (written in C) as parameter, and the function fills
it with data. I tried to convert it and most of it works but the data in the
foot struct is not correct (I believe it's a conversion problem between C#
and C).
The class I created in C# (from the struct) is at the bottom.
typedef struct
{
char iadl1[50+1];
char ictyi[50+1];
char auto_zone_ind;
char retcc;
struct {
char a;
char b;
char c;
char d;
char rsvd3[6];
} foot;
} ZIP4_PARM;
*****************************
/* My struct converted */
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class ZIP4_PARM
{
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=51 )]
public string iadl1;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=51 )]
public string ictyi;
public char auto_zone_ind;
public char retcc;
public footer foot;
public struct footer
{
public char a;
public char b;
public char c;
public char d;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=6)]
public string rsvd3;
}
}