472,332 Members | 1,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,332 software developers and data experts.

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 1771

"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
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');...
57
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...
4
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 =...
3
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...
20
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...
6
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...
0
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...
1
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...
3
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
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.