Re: Class/struct and Marshal.SizeOf
From: SB (stormfire1_at_yahoo.com)
Date: 02/20/05
- Previous message: Jon Skeet [C# MVP]: "Re: ? about web services"
- In reply to: Bob Calvanese: "Re: Class/struct and Marshal.SizeOf"
- Next in thread: Willy Denoyette [MVP]: "Re: Class/struct and Marshal.SizeOf"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 20 Feb 2005 16:31:21 -0500
First, thanks for looking at the code. I'm not sure why you are getting
that error...but I will post the entire MainForm.cs file here which may
help. This compiles and runs fine on my end. Note that some changes were
made today by me but nothing substantial. One thing that may be different
on your end is that I'm using VC# Express and the .NET Framework 2.0b (link
below)...I should have mentioned that before.
http://lab.msdn.microsoft.com/express/vcsharp/default.aspx
Anyway, I've been googling this problem ALL DAY...and I'm beginning to
believe this is a bug in the new framework. However, I'm still hoping that
someone will show me otherwise.
-sb
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
#endregion
namespace MyTestCenter
{
partial class mainForm : Form
{
public mainForm()
{
InitializeComponent();
richTextBox.AppendText("MyStruct size: " +
Marshal.SizeOf(typeof(MyStruct)).ToString());//will show size of 6
richTextBox.AppendText("\nMyClass size: " +
Marshal.SizeOf(typeof(MyClass)).ToString());//will show size of 6
richTextBox.AppendText("\nMyStructTestClass size: " +
Marshal.SizeOf(typeof(MyStructTestClass)).ToString());//will show size of
1536
richTextBox.AppendText("\nMyClassTestClass size: " +
Marshal.SizeOf(typeof(MyClassTestClass)).ToString());//will show size of
1024
}
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)]
public struct MyStruct
{
public short a;
public short b;
public short c;
}
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)]
public class MyClass
{
public short a;
public short b;
public short c;
}
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)]
public class MyStructTestClass
{
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst = 256)]
public MyStruct[] dummy;
}
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)]
public class MyClassTestClass
{
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst = 256)]
public MyClass[] dummy;
}
}
}
- Previous message: Jon Skeet [C# MVP]: "Re: ? about web services"
- In reply to: Bob Calvanese: "Re: Class/struct and Marshal.SizeOf"
- Next in thread: Willy Denoyette [MVP]: "Re: Class/struct and Marshal.SizeOf"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|