I have a C# struct that I pass via UDP to a C++ application. I checked the length of a string field and got different results for the C# and C++ codes. Here are the definitions of the structs:
// C# Side
//-------------
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct stName
{
/// Some data types
[MarshalAs(UnmanagedType.ByValTstr, SizeConst = 20)]
string StringName;
}
// C Side
//---------
struct stName{
/// Some data types
char StringName[20];
When StringName = "192.168.53.2" the size of that field at the C# side is 12 while it is 20 on the C side. What am I doing wrong? If C# uses the actual length of the string, what does the field SizeConst stand for?
LPStr.