473,671 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nested struct array not supported in .net 1.1 managed c++?

I am having this problem in a managed c++ DLL which mixes managed and
unmanaged C/C++ code. I tried to assign value to a struct array nested in
another struct. but I can only write to the first element in array, not the
others.

struct struct2{
int a;
int b;
};
struct struct1 //struct with nested struct2 array
{
struct2 item [10];
} ;

void ComboTest(){
struct1 trans;

//nested struct array. nope.

trans.item[0].a = 1; //assign for item[0] is fine

trans.item[0].b = 10; //assign for item[0] is fine

trans.item[1].a = 2; //assign for item[1] does not work.
trans.item[1].b = 20; //assign for item[1] does not work.

//print out trans.

}
there is no compilation or runtime error. but after the assignment the value
of item[1] just stays unchanged (at default 0s). Is it because nested struct
array is not supported in managed c++? Could anyone shed some light on how to
work around? thanks!

Jan 5 '06 #1
2 1691
"symbol" <sy****@discuss ions.microsoft. com> wrote in message
news:36******** *************** ***********@mic rosoft.com...
there is no compilation or runtime error. but after the assignment the value of item[1] just stays unchanged (at default 0s). Is it because nested
struct
array is not supported in managed c++? Could anyone shed some light on how
to
work around? thanks!


How are you concluding that item[1] wasn't modified?

-cd
Jan 5 '06 #2
"symbol" <sy****@discuss ions.microsoft. com> wrote in message
news:36******** *************** ***********@mic rosoft.com...
I am having this problem in a managed c++ DLL which mixes managed and
unmanaged C/C++ code. I tried to assign value to a struct array nested in
another struct. but I can only write to the first element in array, not
the
others.

struct struct2{
int a;
int b;
};
struct struct1 //struct with nested struct2 array
{
struct2 item [10];
} ;

void ComboTest(){
struct1 trans;

//nested struct array. nope.

trans.item[0].a = 1; //assign for item[0] is fine

trans.item[0].b = 10; //assign for item[0] is fine

trans.item[1].a = 2; //assign for item[1] does not work.
trans.item[1].b = 20; //assign for item[1] does not work.

//print out trans.

}
there is no compilation or runtime error. but after the assignment the
value
of item[1] just stays unchanged (at default 0s). Is it because nested
struct
array is not supported in managed c++? Could anyone shed some light on how
to
work around? thanks!


I cannot reporduce your problem. The code below compiles and works with
VC2003 and VC2005.

Marcus Heege
www.heege.net

<code language="C++/CLI" filename="test. cpp" compileWith="CL /clr test.cpp">
#using <mscorlib.dll >

struct struct2{
int a;
int b;
};
struct struct1 //struct with nested struct2 array
{
struct2 item [10];
} ;

int main()
{
struct1 trans;

//nested struct array. nope.

trans.item[0].a = 1; //assign for item[0] is fine
trans.item[0].b = 10; //assign for item[0] is fine

trans.item[1].a = 2; //assign for item[1] does not work.
trans.item[1].b = 20; //assign for item[1] does not work.

System::Console ::WriteLine(tra ns.item[1].a);
System::Console ::WriteLine(tra ns.item[1].b);
}
</code>
Jan 7 '06 #3

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

Similar topics

8
1675
by: Mike | last post by:
The following struct, DataStruct, is only part of a larger one that contains additional fields and arrays. I need the explicit layout because this struct is really a union, where some of the missing fields and arrays overlap. What's shown here, though, is sufficient for explaining the error. 290 bytes of data come from a serial device and is to be placed in this struct. Hence, I want this struct to be 290 bytes in size, and, if I'm...
5
4314
by: Daniel Brown | last post by:
I am coding a managed C# wrapper for an unmanaged C DLL and I am unable to marshal a structure that contains an array of structures. When executed, the following code throws an ArgumentException with a description “Type ErrorInjectionBuffer can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed.” I have also included snippets from the .H file. Any assistance would be greatly appreciated. ...
5
6306
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and array of UDT.
3
11460
by: GrkEngineer | last post by:
I recently had to use someone's struct from a native app to receive data over Udp. The struct has a array member which looked like this: struct sensorHdr{ char sName; }; When I tried to make this a managed struct by adding either the value struct or ref struct I received a compile error stating that mixed types are not supported. I understand this, but I don't know how to create a char array in
17
1850
by: Aaron | last post by:
I've got a doozie of a problem! I and others have been trying to figure this out for too long and I've come to the conclusion that I should probably look for some support.. Ok, I have a COM component written in C++ (I don't have the source just the binary) and am referencing it from VB. I would say about 99% of the functionality exposed by this COM component works fine from vb .net but I am having a problem calling a method which has a...
9
3134
by: Lonewolf | last post by:
Hi everyone.. I was trying to implement callback fucntions in native codes in my VC8 class, and referred to some online codes which use native class nested within managed class. basically of the form, __gc class CManagedClass { __nogc CNativeClass {
1
4136
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first element in array, not the others. struct struct2{ int a; int b; };
9
2388
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:
6
5875
by: Computer Wizard | last post by:
Hello, I am really scrwed up with the following stuff: struct employee { char* employee_name; }; struct department {
0
8402
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8927
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...
0
8825
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
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
8676
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...
1
6237
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
5703
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
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1816
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.