A
Angel
I converted a C-style struct into C# but when I call a dll function with it
as parm, I get "can not marshal field stack of type ZM7.ZIP4_PARM: This type
can not be marshaled as a structure field.". The dll function was working
great at accessing and reading the struct but then I noticed that I had
commented the member of type struct (trying to run another dll function that
writes to that struct member). When I uncomment it, I get the error.
This is what the struct looks like:
public class ZIP4_PARM
{
public ZIP4_PARM()
{
}
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=51 )]
public string iadl2;
public short respn;
public char retcc;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=86 )]
public string rsvd2;
public footer foot;
public struct footer
{
public char a;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=6)]
public string rsvd3;
}
[MarshalAs(UnmanagedType.ByValArray, SizeConst=10)] //I commented but
then uncommented because function writes to this
public ADDR_REC[] stack;
//I commented but then uncommented because function writes to this
}
public struct ADDR_REC
{
char detail_code;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=6 )]
public string zip_code;
char action_code;
char sec_code;
}
as parm, I get "can not marshal field stack of type ZM7.ZIP4_PARM: This type
can not be marshaled as a structure field.". The dll function was working
great at accessing and reading the struct but then I noticed that I had
commented the member of type struct (trying to run another dll function that
writes to that struct member). When I uncomment it, I get the error.
This is what the struct looks like:
public class ZIP4_PARM
{
public ZIP4_PARM()
{
}
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=51 )]
public string iadl2;
public short respn;
public char retcc;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=86 )]
public string rsvd2;
public footer foot;
public struct footer
{
public char a;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=6)]
public string rsvd3;
}
[MarshalAs(UnmanagedType.ByValArray, SizeConst=10)] //I commented but
then uncommented because function writes to this
public ADDR_REC[] stack;
//I commented but then uncommented because function writes to this
}
public struct ADDR_REC
{
char detail_code;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=6 )]
public string zip_code;
char action_code;
char sec_code;
}