Mario van Zeist

Hello all,

I have come across a strange problem, i am using a 3rd part C++ DLL which requires some structures to be passed, and updates the structures for me. There seems to be a difference when i run the application on a pocketPC or on win32. The size of some structures change depending on which system they are running.

I narrowed it down to the following. The names and size of the structures have been cutdown and changed to protect the innocent.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]

internal unsafe struct yetAnotherStruct

{

public int Number;

public fixed int Numbers[32];

}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]

internal struct ICanSizeMe

{

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]

public string text;

public yetAnotherStruct structo;

}

When you now run this code on a PPC

MessageBox.Show(Marshal.SizeOf(typeof(ICanSizeMe)).ToString())

It will report a size of 264 bytes (which is incorrect), running the same exe on Win32 will give a size of 388 bytes (correct).

its a Unicode string of 128 chars (128*2)=256

+ The size of yetAnotherStruct(1 int=4 + array of 32 ints=128 bytes)

so 4+128+256=388

It seems like its not inlining the Numbers property of the yetAnotherStruct on CF, but it's inlining it in the Full Framework. without changing the executable.

is this a possible problem with CF, or am i doing something wrong.



Re: .NET Compact Framework Compact and Full framework have different sizes of structure

ScubaSteve20001

It may very well be either a bug or a limitation of the CF. It looks like the problem lies in your 'yetAnotherStruct' with your numbers array. Try something like this instead to see if it works:


internal unsafe struct yetAnotherStruct
{
public int Number;

[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public int [] Numbers;
}





Re: .NET Compact Framework Compact and Full framework have different sizes of structure

Ilya Tumanov

No, youre not doing anything wrong and it is indeed an issue with NETCF (I've filed a bug).

Youd need to do it differently as a workaround:

Code Snippet

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct yetAnotherStruct
{
public int Number;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public int[] Numbers;
}






Re: .NET Compact Framework Compact and Full framework have different sizes of structure

Mario van Zeist

I suspected as much,

Thnx for the quick help.