473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Marshal.SizeOf

Below is my unmanaged structure:

Expand|Select|Wrap|Line Numbers
  1.     [StructLayout(LayoutKind.Sequential, Pack = 1)]
  2.     public struct LasHeader
  3.     {
  4.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
  5.         public string FileSignature;
  6.  
  7.         [MarshalAs(UnmanagedType.U2)]
  8.         public UInt16 FileSourceId;
  9.  
  10.         [MarshalAs(UnmanagedType.U2)]
  11.         public ushort Reserved;
  12.  
  13.         [MarshalAs(UnmanagedType.U4)]
  14.         public ulong ProjectId1;
  15.  
  16.         [MarshalAs(UnmanagedType.U2)]
  17.         public ushort ProjectId2;
  18.  
  19.         [MarshalAs(UnmanagedType.U2)]
  20.         public ushort ProjectId3;
  21.  
  22.         [MarshalAs(UnmanagedType.U1, SizeConst = 8)]
  23.         public byte[] ProjectId4;
  24.  
  25.         [MarshalAs(UnmanagedType.U1)]
  26.         public byte VersionMajor;
  27.  
  28.         [MarshalAs(UnmanagedType.U1)]
  29.         public byte VersionMinor;
  30.  
  31.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
  32.         public string SystemIdentifier;
  33.  
  34.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
  35.         public string GeneratingSoftware;
  36.  
  37.         [MarshalAs(UnmanagedType.U2)]
  38.         public ushort FileCreationDayOfYear;
  39.  
  40.         [MarshalAs(UnmanagedType.U2)]
  41.         public ushort FileCreationYear;
  42.  
  43.         [MarshalAs(UnmanagedType.U2)]
  44.         public ushort HeaderSize;
  45.  
  46.         [MarshalAs(UnmanagedType.U4)]
  47.         public ulong OffsetToData;
  48.  
  49.         [MarshalAs(UnmanagedType.U4)]
  50.         public ulong NumberOfVariableLengthRecords;
  51.  
  52.         [MarshalAs(UnmanagedType.U1)]
  53.         public byte PointDataFormatId;
  54.  
  55.         [MarshalAs(UnmanagedType.U2)]
  56.         public ushort PointDataRecordLength;
  57.  
  58.         [MarshalAs(UnmanagedType.U4)]
  59.         public ulong NumberOfPointRecords;
  60.  
  61.         [MarshalAs(UnmanagedType.U4, SizeConst = 5)]
  62.         public ulong[] NumberOfPointByReturn;
  63.  
  64.         [MarshalAs(UnmanagedType.R8)]
  65.         public double XScaleFactor;
  66.  
  67.         [MarshalAs(UnmanagedType.R8)]
  68.         public double YScaleFactor;
  69.  
  70.         [MarshalAs(UnmanagedType.R8)]
  71.         public double ZScaleFactor;
  72.  
  73.         [MarshalAs(UnmanagedType.R8)]
  74.         public double XOffset;
  75.  
  76.         [MarshalAs(UnmanagedType.R8)]
  77.         public double YOffset;
  78.  
  79.         [MarshalAs(UnmanagedType.R8)]
  80.         public double ZOffset;
  81.  
  82.         [MarshalAs(UnmanagedType.R8)]
  83.         public double MaxX;
  84.  
  85.         [MarshalAs(UnmanagedType.R8)]
  86.         public double MinX;
  87.  
  88.         [MarshalAs(UnmanagedType.R8)]
  89.         public double MaxY;
  90.  
  91.         [MarshalAs(UnmanagedType.R8)]
  92.         public double MinY;
  93.  
  94.         [MarshalAs(UnmanagedType.R8)]
  95.         public double MaxZ;
  96.  
  97.         [MarshalAs(UnmanagedType.R8)]
  98.         public double MinZ;
  99.     }
  100.  
When I try to get the size of this struct using Marshal.SizeOf(), I get the following ArgumentException:

Type 'LasHeader' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.

Any ideas ?


Thank you.
Sep 18 '07 #1
0 1450

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: William Stacey | last post by:
Using the following struct def, how can I tell (using reflection) if "ba" has the marshal attribute and get the "ByValArray" and maybe even the size? In the bigger picture, given a struct (or a...
2
by: Beringer | last post by:
Why do I get the following run time error: Additional information: Type System.Object can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed. When the...
6
by: SB | last post by:
I feel dumb to ask because I bet this is a simple question... Looking at the code below, can someone please explain why I get two different values in my Marshal.SizeOf calls (see the commented...
1
by: Claire | last post by:
char a = 'p'; if (System.Runtime.InteropServices.Marshal.SizeOf(a) == 1) dothis(); else dothat(); SizeOf(a) is returned as 1. I thought chars were 16 bits in size. Why is it returning 1 to me?...
6
by: Howard Kaikow | last post by:
Given: private struct PROCESSENTRY32 { public int dwSize; public int cntUsage; public int th32ProcessID; public int th32DefaultHeapID; public int th32ModuleID;
4
by: marcosegurini | last post by:
Hi. Is is possible to mark a class-member-variable to avoid its marshaling? class MyClass { int i_; IntPtr point_;
2
by: scottt | last post by:
I need to call into a C++ DLL from my C# code. The function is expecting a void pointer to an unsigned short. Which would be more correct? UInt16 wRegData; IntPtr p =...
2
by: RYoung | last post by:
Given this native struct: typedef struct vendor { char name; } VENDOR I want to make managed equivalent, so I did this: public value struct Vendor
0
by: Charming12 | last post by:
Hi All, I have a strange problem and due to my inefficiency with IntPtr i am unable to figure it out. I have an structure something like: public struct Detail { public int age; public...
1
by: Charming12 | last post by:
Hi All, I am using System.Runtime.InteropServices; to marshal a structure using Marshal.structureToPtr(). But to get the size of structure when i get Marshal.sizeOf(), it gives me improper sizes....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.