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

Home Posts Topics Members FAQ

Problem with importing nested C struct with char*

Need help quick!!! Am really stuck on this problem!

I have a C dll, and it uses a nested struct. (see below) The struct has 2
layers of nested structs. The first field in the first struct is a char*.
I used StructLayout.Se quential to port each of the structs to C#, and I used
UnmanagedType.L PStr to marshal the char* to C# string, but the resulting
struct data are stored wrong when passed into the dll's api call. The char*
is returning ok because it's at the first field, but none of the other
fields are correct. One field actually showed up where another field should
have been in the assembly. The results are the same if I don't use
UnmanagedType.L PStr marshaling. Can someone explain why my coding have
things all messed up? Is there a "right" way to do what I am doing?

C struct:
typedef struct Control
{
struct
{
char *version;

struct
{
long version;
long option;
} mystruct3;

} mystruct1;

struct
{
long version;

struct
{
long version;
char revision;
long subRevision;
} mystruct4;

} mystruct2;
}

C#:
[StructLayout(La youtKind.Sequen tial)]
public struct Control
{
public s1 mystruct1;
public s2 mystruct2;
}

[StructLayout(La youtKind.Sequen tial)]
public struct s1
{
[MarshalAs(Unman agedType.LPStr)]
public string version;
public s3 mystruct3;
}

[StructLayout(La youtKind.Sequen tial)]
public struct s3
{
public int version;
public int option;
}

[StructLayout(La youtKind.Sequen tial)]
public struct s2
{
public int version;
public s4 mystruct4;
}

[StructLayout(La youtKind.Sequen tial)]
public struct s4
{
public int version;
public byte revision;
public int subRevision
}
Nov 15 '05 #1
0 1345

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

Similar topics

11
1994
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
14
5217
by: ser | last post by:
hi this is the code that i have but i seem to have 2 errors and i dont understand were they are so can some one please help me. thanks this is the code #include<iostream.h> #include<conio.h> struct faculty { char fact1; char fact2;
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 {
2
2457
by: samba | last post by:
I having a nested structures which are referenced with pointer variables #include <stdio.h> struct test { int i; char *mytest; }; struct sample {
3
6669
by: Amit_Basnak | last post by:
Dear Friends I have the follwoing function "tss_fe_get_own_info" which has the arguments as shows below tss_fe_get_own_info(char *user_id, tss_user_profile_t **p_buf_UserSecInfo, error_status_t *retStatus) // Structure tss_user_profile_t from the function typedef struct {
2
2403
by: yannick.beot | last post by:
Hi, I have a problem with nested namespace in a schema. I defined a schema A. A is importing a schema B with the namespace nsB and a schema C with the namespace nsC. But both B and C are importing a schema D with a namespace D. I have a validation error because some elements are defined twice.
3
1777
by: Vasu | last post by:
Hi! Can anybody there help me in analysis of the following code, which is a structure of customer's details, asks user to fill in the no. of customers and then their details. When I put in no. of customer as 2 and start filling in users details, in the detail of second customer till the name of State is OK as soon as I fill in the detail of State and press enter, it shows the field of PIN code but then suddenly it says something like...
4
2773
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never done this before, I'm sure it's a rookie mistake but I cannot seem to find it. Can someone render some assistance please? struct Fpos { grib_handle *h;
5
1906
by: bitstreamer | last post by:
Greetings. The emulation fever has conquered all kinds of Internet communities, and hence I've decided to write a tool in C which can read and modify a disk image. (However, I won't tell which kind of disk images until it's finished. Only problem I have now, where do I start and where do I have to malloc() and where not? It's better to know about this in the concept phase, for when the tool goes beyond the magical 1000-lines extent, it...
0
8914
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
8820
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
8598
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
7433
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
6223
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
5695
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
4224
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
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1809
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.