O
Olaf Baeyens
I am trying to port some C++ structures to C# but I have troubles with this
one.
Note: this is a file record, so I must keep this format.
#pragma pack( push, 1 )
typedef struct {
char title[80];
DWORD dwCount;
} STLHEADER, *LPSTLHEADER;
#pragma pack( pop )
Using Google I discovered that this could be ported to this C# variant,
note the 'Marshal' to create a 80 byte array.
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct STLHEADER {
[MarshalAs (UnmanagedType.U1, SizeConst=80)]
public char[] title;
public int dwCount;
}
So far so good, but now I am stuck on this line "sizeof(STLHEADER)" needed
in a unsafe function.
error CS0208: Cannot take the address or size of a variable of a managed
type ('MySpace.STLHEADER')
And it has something to do with the Marshal thing.
I could replace the "sizeof(STLHEADER)" with 80+4 but I would really prefer
to have a more professional sollution.
Maybe there is another alternative way to define a 'char title[80]' byte
array?
Thanks for any feedback.
one.
Note: this is a file record, so I must keep this format.
#pragma pack( push, 1 )
typedef struct {
char title[80];
DWORD dwCount;
} STLHEADER, *LPSTLHEADER;
#pragma pack( pop )
Using Google I discovered that this could be ported to this C# variant,
note the 'Marshal' to create a 80 byte array.
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct STLHEADER {
[MarshalAs (UnmanagedType.U1, SizeConst=80)]
public char[] title;
public int dwCount;
}
So far so good, but now I am stuck on this line "sizeof(STLHEADER)" needed
in a unsafe function.
error CS0208: Cannot take the address or size of a variable of a managed
type ('MySpace.STLHEADER')
And it has something to do with the Marshal thing.
I could replace the "sizeof(STLHEADER)" with 80+4 but I would really prefer
to have a more professional sollution.
Maybe there is another alternative way to define a 'char title[80]' byte
array?
Thanks for any feedback.
