473,757 Members | 7,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(La youtKind.Sequen tial)]
struct InnerStruct
{
Int32 member1;
....
};
struct OuterStruct
{
Int32 member1;
....
[MarshalAs(Unman agedType.ByValA rray, 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 3146
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******@myrea lbox.com> wrote in message
news:bf******** *************** ***@posting.goo gle.com...
"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 "Directorie s" 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
1939
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 = struct.pack('iiii', 1, 2, 3, 4) >>> struct.unpack('i(ii)i', data) # Note the parentheses (1, (2, 3), 4)
0
1113
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 structs that have arraylist fields. What I want to do is to have a ShoppingBasket that will hold any number of Itemstructs and an AllShoppingBaskets that will hold all the ShoppingBaskets. The resulting XML I am after should look like this.
10
3244
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 complexity analyzer tool supposedly does not pick it up. Is it really more efficient? Personally I find this coding style extremely cryptic, misleading and error-prone. I believe that I have removed all traces of proprietary-ness from this coding...
6
2176
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. thank you.
0
1385
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 structuers contain mostly StringBuilder objects, but some contain arrays of other structs that themselves contain StringBuilder objects. I have defined the stucts in the C++ header file as typedef __gc StructName {
4
1974
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 their head, do they? Many thanks! -- Best Regards,
5
96494
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 what it is. Is converting a C-style struct to a C# class (or struct) marshalling? And what about the function exports? Are those Marshalling too? Thanks for your help and thanks for helping me with the Dll exports (the several messages I posted in...
3
3641
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
2397
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 that I use to communicate to some unmanaged code in a DLL written in C. It is not complicated, but will change and I would like to be able to sequentially access it without explicitly referring to each and every element. Here is the structure:
0
9489
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...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
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...
0
6562
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
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.