473,805 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Marshal.SizeOf

1 New Member
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 ArgumentExcepti on:

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 1499

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

Similar topics

4
3828
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 class), how to decide if "sizeof(MyStruct)" would fail before calling sizeof and having to use Marshal.sizeof? TIA public struct MyStruct {
2
9232
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 following code is executed? object test = new object(); int temp = Marshal.SizeOf(test);
6
10820
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 lines)? TIA! sb
1
4196
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? thanks Claire
6
6698
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
1558
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
8146
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 = Marshal.AllocHGlobal(Marshal.SizeOf(wRegData)); Marshal.StructureToPtr(wRegData, p, false);
2
3189
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
2138
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 Detail(int _age)
1
2395
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. Code: public struct IDName { public ushort Id;
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.