473,508 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ struct transparency in C#

In a C++ project, I have the following struct definition:

struct GridModeDataT
{
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
};

I did a Managed C++ wrapper class around my C++ project. This MC++
wrapper defines a virtual function 'OnGetGridModeParamsAnswer()', which
uses a parameter of the above struct type.

Finally, in a C# project, I inherit from the class in the MC++ project
and override the virtual function, as shown here:

public override void OnGetGridModeParamsAnswer(GridModeDataT gridModeData)
{
Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

Everything compiles and runs correctly. If I look to 'gridModeData'
within the debuggers 'Watch' window, the struct members are correctly
resolved and assigned. For example it looks as follows in the watch window:

gridModeData {GridModeDataT} GridModeDataT
bUseRegion 0 int
dVal1 1.0 double
dVal2 2.0 double
dVal3 3.0 double
lNumberOfPoints 4 int
regionType 1 ES_RegionType

Now the problem: If I try to reference the struct members in C# code,
the compiler says there are no such members:

public override void OnGetGridModeParamsAnswer(GridModeDataT
gridModeData)
{
double dVal1 = gridModeData.dVal1; // compiler says:
'GridModeDataT' does not contain a definition for 'dVal1'

Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

The 'intellisense' only offers the the following methods on
gridModeData: 'Equals', 'GetHashCode', 'GetType', 'ToString'.
I don't understand why I can't access the 'original' struct members,
although the debugger can 'see' them.

How do I have to work around this problem?

Any help is appreciated.
Regards Urs

Nov 15 '05 #1
7 1860

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:Ow****************@TK2MSFTNGP10.phx.gbl...
In a C++ project, I have the following struct definition:

struct GridModeDataT
{
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
};

I did a Managed C++ wrapper class around my C++ project. This MC++
wrapper defines a virtual function 'OnGetGridModeParamsAnswer()', which
uses a parameter of the above struct type.

Finally, in a C# project, I inherit from the class in the MC++ project
and override the virtual function, as shown here:

public override void OnGetGridModeParamsAnswer(GridModeDataT gridModeData) {
Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

Everything compiles and runs correctly. If I look to 'gridModeData'
within the debuggers 'Watch' window, the struct members are correctly
resolved and assigned. For example it looks as follows in the watch window:
gridModeData {GridModeDataT} GridModeDataT
bUseRegion 0 int
dVal1 1.0 double
dVal2 2.0 double
dVal3 3.0 double
lNumberOfPoints 4 int
regionType 1 ES_RegionType

Now the problem: If I try to reference the struct members in C# code,
the compiler says there are no such members:

public override void OnGetGridModeParamsAnswer(GridModeDataT
gridModeData)
{
double dVal1 = gridModeData.dVal1; // compiler says:
'GridModeDataT' does not contain a definition for 'dVal1'

Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

The 'intellisense' only offers the the following methods on
gridModeData: 'Equals', 'GetHashCode', 'GetType', 'ToString'.
I don't understand why I can't access the 'original' struct members,
although the debugger can 'see' them.

How do I have to work around this problem?
I know this is a stupid question...but are the fields public?
Any help is appreciated.
Regards Urs

Nov 15 '05 #2
Thanks for the answer. I don't agree this is a stupid question. But I
think the compiler would come up with some kind of
'cannot access private members' error message. I thought struct members
in C++ are all public by default. Anyway, I tried with

struct GridModeDataT
{
public:
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
}

but it didn't solve my problem.
Daniel O'Connell wrote:
"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:Ow****************@TK2MSFTNGP10.phx.gbl...

In a C++ project, I have the following struct definition:

struct GridModeDataT
{
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
};

I did a Managed C++ wrapper class around my C++ project. This MC++
wrapper defines a virtual function 'OnGetGridModeParamsAnswer()', which
uses a parameter of the above struct type.

Finally, in a C# project, I inherit from the class in the MC++ project
and override the virtual function, as shown here:

public override void OnGetGridModeParamsAnswer(GridModeDataT

gridModeData)

{
Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

Everything compiles and runs correctly. If I look to 'gridModeData'
within the debuggers 'Watch' window, the struct members are correctly
resolved and assigned. For example it looks as follows in the watch

window:

gridModeData {GridModeDataT} GridModeDataT
bUseRegion 0 int
dVal1 1.0 double
dVal2 2.0 double
dVal3 3.0 double
lNumberOfPoints 4 int
regionType 1 ES_RegionType

Now the problem: If I try to reference the struct members in C# code,
the compiler says there are no such members:

public override void OnGetGridModeParamsAnswer(GridModeDataT
gridModeData)
{
double dVal1 = gridModeData.dVal1; // compiler says:
'GridModeDataT' does not contain a definition for 'dVal1'

Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

The 'intellisense' only offers the the following methods on
gridModeData: 'Equals', 'GetHashCode', 'GetType', 'ToString'.
I don't understand why I can't access the 'original' struct members,
although the debugger can 'see' them.

How do I have to work around this problem?

I know this is a stupid question...but are the fields public?
Any help is appreciated.
Regards Urs



Nov 15 '05 #3
Hmm, I'm just learning Managed C++ myself, so I don't know for sure what the
defaults are(I'm in the explicitly declare access camp when it comes to C++
because its so easy), but a few things that may be the issue. Is
GridModeDataT a managed struct? (either using __gc or __valuetype, I'm not
sure, like I said, I'm still learning) and can you access the members from a
derived class written in C++?

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Thanks for the answer. I don't agree this is a stupid question. But I think
the compiler would come up with some kind of
'cannot access private members' error message. I thought struct members in
C++ are all public by default. Anyway, I tried with

struct GridModeDataT
{
public:
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
}

but it didn't solve my problem.
Daniel O'Connell wrote:

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:Ow****************@TK2MSFTNGP10.phx.gbl...

In a C++ project, I have the following struct definition:

struct GridModeDataT
{
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
};

I did a Managed C++ wrapper class around my C++ project. This MC++
wrapper defines a virtual function 'OnGetGridModeParamsAnswer()', which
uses a parameter of the above struct type.

Finally, in a C# project, I inherit from the class in the MC++ project
and override the virtual function, as shown here:

public override void OnGetGridModeParamsAnswer(GridModeDataT

gridModeData)

{
Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

Everything compiles and runs correctly. If I look to 'gridModeData'
within the debuggers 'Watch' window, the struct members are correctly
resolved and assigned. For example it looks as follows in the watch

window:

gridModeData {GridModeDataT} GridModeDataT
bUseRegion 0 int
dVal1 1.0 double
dVal2 2.0 double
dVal3 3.0 double
lNumberOfPoints 4 int
regionType 1 ES_RegionType

Now the problem: If I try to reference the struct members in C# code,
the compiler says there are no such members:

public override void OnGetGridModeParamsAnswer(GridModeDataT
gridModeData)
{
double dVal1 = gridModeData.dVal1; // compiler says:
'GridModeDataT' does not contain a definition for 'dVal1'

Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

The 'intellisense' only offers the the following methods on
gridModeData: 'Equals', 'GetHashCode', 'GetType', 'ToString'.
I don't understand why I can't access the 'original' struct members,
although the debugger can 'see' them.

How do I have to work around this problem?
I know this is a stupid question...but are the fields public?
Any help is appreciated.
Regards Urs



Nov 15 '05 #4
Not sure if C++ works the same but in C# you need to specify every single
field as public

struct GridModeDataT
{
public double dVal1;
public double dVal2;
public double dVal3;
public long lNumberOfPoints;
public int bUseRegion;
}

Anything not made public is treated as private.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5
Urs,
How do I have to work around this problem?


Try adding the __value keyword

__value struct GridModeDataT

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #6
Hi Daniel,

No, GridModeDataT is not a managed struct. My intention was to use C/C++
legay code unchanged in C# as far as possible. Although I had a bad
feeling about this, I just tried. And I wondered why neither the
compiler complained about the signature of
OnGetGridModeParamsAnswer(GridModeDataT gridModeData), nor there was a
problem at runtime. Memory layout of gridModeData is as expected (when
looked at it thru debugger) when OnGetGridModeParamsAnswer gets called.
The only problem is that I cannot access the struct members in C# code
syntactically. I'm afraid I'll have to wrap all my legacy C++ structs to
managed C++ structs ?
Daniel O'Connell wrote:
Hmm, I'm just learning Managed C++ myself, so I don't know for sure what the
defaults are(I'm in the explicitly declare access camp when it comes to C++
because its so easy), but a few things that may be the issue. Is
GridModeDataT a managed struct? (either using __gc or __valuetype, I'm not
sure, like I said, I'm still learning) and can you access the members from a
derived class written in C++?

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Thanks for the answer. I don't agree this is a stupid question. But I think
the compiler would come up with some kind of
'cannot access private members' error message. I thought struct members in
C++ are all public by default. Anyway, I tried with

struct GridModeDataT
{
public:
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
}

but it didn't solve my problem.
Daniel O'Connell wrote:

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:Ow****************@TK2MSFTNGP10.phx.gbl...

In a C++ project, I have the following struct definition:

struct GridModeDataT
{
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
};

I did a Managed C++ wrapper class around my C++ project. This MC++
wrapper defines a virtual function 'OnGetGridModeParamsAnswer()', which
uses a parameter of the above struct type.

Finally, in a C# project, I inherit from the class in the MC++ project
and override the virtual function, as shown here:

public override void OnGetGridModeParamsAnswer(GridModeDataT

gridModeData)

{
Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

Everything compiles and runs correctly. If I look to 'gridModeData'
within the debuggers 'Watch' window, the struct members are correctly
resolved and assigned. For example it looks as follows in the watch

window:

gridModeData {GridModeDataT} GridModeDataT
bUseRegion 0 int
dVal1 1.0 double
dVal2 2.0 double
dVal3 3.0 double
lNumberOfPoints 4 int
regionType 1 ES_RegionType

Now the problem: If I try to reference the struct members in C# code,
the compiler says there are no such members:

public override void OnGetGridModeParamsAnswer(GridModeDataT
gridModeData)
{
double dVal1 = gridModeData.dVal1; // compiler says:
'GridModeDataT' does not contain a definition for 'dVal1'

Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

The 'intellisense' only offers the the following methods on
gridModeData: 'Equals', 'GetHashCode', 'GetType', 'ToString'.
I don't understand why I can't access the 'original' struct members,
although the debugger can 'see' them.

How do I have to work around this problem?
I know this is a stupid question...but are the fields public?
Any help is appreciated.
Regards Urs




Nov 15 '05 #7

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Daniel,

No, GridModeDataT is not a managed struct. My intention was to use C/C++
legay code unchanged in C# as far as possible. Although I had a bad
feeling about this, I just tried. And I wondered why neither the
compiler complained about the signature of
OnGetGridModeParamsAnswer(GridModeDataT gridModeData), nor there was a
problem at runtime. Memory layout of gridModeData is as expected (when
looked at it thru debugger) when OnGetGridModeParamsAnswer gets called.
The only problem is that I cannot access the struct members in C# code
syntactically. I'm afraid I'll have to wrap all my legacy C++ structs to
managed C++ structs ? You probably will, I would guess the C++ compiler handles that through IJW,
even though it doesn't work...I dunno, I'm still learning like I said, ;).

Daniel O'Connell wrote:
Hmm, I'm just learning Managed C++ myself, so I don't know for sure what thedefaults are(I'm in the explicitly declare access camp when it comes to C++because its so easy), but a few things that may be the issue. Is
GridModeDataT a managed struct? (either using __gc or __valuetype, I'm notsure, like I said, I'm still learning) and can you access the members from aderived class written in C++?

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Thanks for the answer. I don't agree this is a stupid question. But I thinkthe compiler would come up with some kind of
'cannot access private members' error message. I thought struct members inC++ are all public by default. Anyway, I tried with

struct GridModeDataT
{
public:
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
}

but it didn't solve my problem.
Daniel O'Connell wrote:

"Urs Wigger" <ns_urs.wigger@leica-geosystems_ns.com> wrote in message
news:Ow****************@TK2MSFTNGP10.phx.gbl...

In a C++ project, I have the following struct definition:

struct GridModeDataT
{
double dVal1;
double dVal2;
double dVal3;
long lNumberOfPoints;
int bUseRegion;
enum ES_RegionType regionType;
};

I did a Managed C++ wrapper class around my C++ project. This MC++
wrapper defines a virtual function 'OnGetGridModeParamsAnswer()', which
uses a parameter of the above struct type.

Finally, in a C# project, I inherit from the class in the MC++ project
and override the virtual function, as shown here:

public override void OnGetGridModeParamsAnswer(GridModeDataT

gridModeData)

{
Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

Everything compiles and runs correctly. If I look to 'gridModeData'
within the debuggers 'Watch' window, the struct members are correctly
resolved and assigned. For example it looks as follows in the watch

window:

gridModeData {GridModeDataT} GridModeDataT
bUseRegion 0 int
dVal1 1.0 double
dVal2 2.0 double
dVal3 3.0 double
lNumberOfPoints 4 int
regionType 1 ES_RegionType

Now the problem: If I try to reference the struct members in C# code,
the compiler says there are no such members:

public override void OnGetGridModeParamsAnswer(GridModeDataT
gridModeData)
{
double dVal1 = gridModeData.dVal1; // compiler says:
'GridModeDataT' does not contain a definition for 'dVal1'

Console.WriteLine("Derived OnGetGridModeParamsAnswer() was called");
}

The 'intellisense' only offers the the following methods on
gridModeData: 'Equals', 'GetHashCode', 'GetType', 'ToString'.
I don't understand why I can't access the 'original' struct members,
although the debugger can 'see' them.

How do I have to work around this problem?
I know this is a stupid question...but are the fields public?
Any help is appreciated.
Regards Urs



Nov 15 '05 #8

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

Similar topics

2
5650
by: Cecile Muller | last post by:
I've been trying to just open a png and display it, that way: <? header ("Content-type: image/png"); $im = imagecreatefrompng('empty.png'); imagepng($im); ?> But the transparency is not...
57
3903
by: Piotr Wolski | last post by:
how to make my page that it was correct with every browser standard? for example when i change HTML's table size it has no effect when i see it under mozilla and has effect under Internet...
4
3300
by: Matthias Czapla | last post by:
Hi! I want to resize uploaded GIF images. Currently I do it like this: <?php // ... $img = imagecreatefromgif($path); $img_scaled = imagecreate($new_width, $new_height);...
3
3848
by: Mr. x | last post by:
Hello, I would like that my image's background color will be transparent. What I have is only paintbrush. My image is *.jpg format (I have tried to save it as *.gif format, and I got less...
20
4472
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic...
6
3643
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the...
0
1293
by: ZikO | last post by:
Hi. I've experienced one problem. Im using three froms. Two of them are maximized, whereas one is normal form with transparency. Transparency stops working, that is I can see the color which...
1
2696
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
3
4199
by: Martijn Mulder | last post by:
When I populate a ToolStrip with ToolStripButtons with a .png-image on it, will Windows understand the transparency of the .png file?
0
7227
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
7331
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
7501
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...
0
5633
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,...
1
5056
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...
0
4713
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...
0
3204
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...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
768
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.