473,387 Members | 1,864 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,387 software developers and data experts.

Marshaling Nested Structs

Hi all,

I read some Q&As in the Net, discussing Marshalization of nested
structs in C# (or VB.NET). Some guys stated that .NET framework does
not support this feature yet. Are they right?

BTW, by nested structs I mean structures such as this:

[StructLayout(LayoutKind.Sequential)]
struct InnerStruct
{
Int32 member1;
....
};
struct OuterStruct
{
Int32 member1;
....
[MarshalAs(UnmanagedType.ByValArray, SizeConst=15)]
InnerStruct[] innerStruct;
};

I tried marshaling the above code, and I receivied an error message
when I tried to get the size of OuterStruct using Marshal.SizeOf()
function.

Is there a way to work around this?
(If possible, please give more more than just some hints, 'coz I'm
totally new to marshaling)

Thnx in advanced
MSD.
Nov 16 '05 #1
4 3115
Hi MSDousti,

I'm far from any expert on Marshalling, but if you set the innerstruct member as a byte array you should be able to copy the data to an innerstruct using Marshal.Copy or the opposite if you prefer.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
"Morten Wennevik" <Mo************@hotmail.com> wrote in message news:
I'm far from any expert on Marshalling, but if you set the innerstruct member as a byte array you should be able to copy the data to an innerstruct using Marshal.Copy or the opposite if you prefer.


Of course, but that'll be a pity if .NET does not support such
important (for API programming or so) structures.

Yours,
MSD.
Nov 16 '05 #3
The overall purpose of an OO development environment like .NET is to get rid
of the C-API programming paradigm in its supported languages, not to offer a
set of new languages for this same C-API programming style.
However, if you need this kind of interop support and you don't want to use
what's offered by the InteropServices.Marshal class to do your own
marshaling, .NET has excellent support , you just have to use the right
language tool which is MC++ or the upcoming C++/CLI binding.

Willy.

"MSDousti" <MS******@myrealbox.com> wrote in message
news:bf**************************@posting.google.c om...
"Morten Wennevik" <Mo************@hotmail.com> wrote in message news:
I'm far from any expert on Marshalling, but if you set the innerstruct
member as a byte array you should be able to copy the data to an
innerstruct using Marshal.Copy or the opposite if you prefer.


Of course, but that'll be a pity if .NET does not support such
important (for API programming or so) structures.

Yours,
MSD.

Nov 16 '05 #4
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message > The overall purpose of an OO development environment like .NET is to get rid
of the C-API programming paradigm in its supported languages, not to offer a
set of new languages for this same C-API programming style.
Thnx Willy,
I want to use nested structs not only to call C-Style APIs, but to
read a file header (In fact, PE files). Some predefined structures
like "Directories" in PE file header, use nested structs (for more
info, u can look at "Optinal Header" in WINNT.H or PE_and_COFF
specification by MS).
However, if you need this kind of interop support and you don't want to use
what's offered by the InteropServices.Marshal class to do your own
marshaling, .NET has excellent support , you just have to use the right
language tool which is MC++ or the upcoming C++/CLI binding.


In fact I hate C/C++ style, and love C# (& VB.NET). It's so easy to
learn and program. So I'm seeking ways to port early codes to the new
style.

BTW: I wish the framework was installed on my WIN98/XP by default!
(Longhorn is said to support this feature)

OK, any suggestion for reading PE headers when encountering nested
structs?
thnx, anyway.
MSD.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matthew Barnes | last post by:
I was wondering if there would be any interest in extending the struct.unpack format notation to be able to express groups of data with parenthesis. For example: >>> data =...
0
by: Alexandros__ | last post by:
Hello everyone, I am using the Configuration Application block to write an XML configuration file for my application. Most of it is working fine but I have a problem serialising some nested...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
6
by: jwvai316 | last post by:
I don't really know how to say it so I just say it a nested linklist. How do you make LinkLists inside LinkList? Can anyone help me for this? I think an example program will help me a lot. ...
0
by: Arthur Autenzio | last post by:
I have written a managed C++ wrapper class around an old C++ DLL that I have to use in my application. My problem is I need to marshal a bunch of structures from C# to the C++ class. These...
4
by: Christopher Ireland | last post by:
Hi -- I'm trying to find an example of a nested class implemented within the .NET Framework itself but without much success. I don't suppose that anybody knows of such an example off the top of...
5
by: VM | last post by:
What's marshalling? I've had to use it extensively for a project but I don't know what it means. I tried to look for a definition in the Internet but I couldn't find anything that would explain...
3
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
9
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.