473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

pointer to pointer to a managed class

Hello,

I want a member in my class that will save pointer to pointer to
System::Drawing::Image class.
When I write on my class code:

System::Drawing::Image **bmp;

I get this error message:
error C3160: 'bmp' : cannot declare interior __gc pointer or reference as a
member of 'RCClientNS::RCClientComm'.

What is the solution?

Thank's alot,
Itay.
Nov 16 '05 #1
6 2257
Use the provided (in vcclr.h) template gcroot<T> as the member of the unmanaged class. This allows the garbage collector to track the reference to the
managed object (so it can be updated if/when the GC decides to move the object).
See an example below.

Adam Mitz
Microsoft

#include <vcclr.h>
#using <mscorlib.dll>

using namespace System;

__nogc class UM{
public:
gcroot<Object*> ptr;
};

__gc class M{
public:
String* data;
void SetData(String* in_data){
data = in_data;
}
String* ToString(){
return data;
}
};

int _tmain()
{
M* m = new M;
m->SetData(S"Hello World!");
UM um;
um.ptr = m;
Console::WriteLine(um.ptr->ToString());
return 0;
}
--------------------
Reply-To: "Itay_k" <it****@walla.co.il>
From: "Itay_k" <it****@walla.co.il>
Subject: pointer to pointer to a managed class
Date: Mon, 28 Jul 2003 13:35:13 +0200
Lines: 18
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <##**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: 80.178.8.240.forward.012.net.il 80.178.8.240
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26587
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

Hello,

I want a member in my class that will save pointer to pointer to
System::Drawing::Image class.
When I write on my class code:

System::Drawing::Image **bmp;

I get this error message:
error C3160: 'bmp' : cannot declare interior __gc pointer or reference as a
member of 'RCClientNS::RCClientComm'.

What is the solution?

Thank's alot,
Itay.

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Nov 16 '05 #2
Thanks you, but my class is managed.
I need to add this member (pointer to pointer) to a managed class, so why it
isn't working?

Itay.


"Adam Mitz [MSFT]" <t-****@microsoft.com> wrote in message
news:Fb**************@cpmsftngxa06.phx.gbl...
Use the provided (in vcclr.h) template gcroot<T> as the member of the unmanaged class. This allows the garbage collector to track the reference
to the managed object (so it can be updated if/when the GC decides to move the object). See an example below.

Adam Mitz
Microsoft

#include <vcclr.h>
#using <mscorlib.dll>

using namespace System;

__nogc class UM{
public:
gcroot<Object*> ptr;
};

__gc class M{
public:
String* data;
void SetData(String* in_data){
data = in_data;
}
String* ToString(){
return data;
}
};

int _tmain()
{
M* m = new M;
m->SetData(S"Hello World!");
UM um;
um.ptr = m;
Console::WriteLine(um.ptr->ToString());
return 0;
}
--------------------
Reply-To: "Itay_k" <it****@walla.co.il>
From: "Itay_k" <it****@walla.co.il>
Subject: pointer to pointer to a managed class
Date: Mon, 28 Jul 2003 13:35:13 +0200
Lines: 18
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <##**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: 80.178.8.240.forward.012.net.il 80.178.8.240
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26587
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

Hello,

I want a member in my class that will save pointer to pointer to
System::Drawing::Image class.
When I write on my class code:

System::Drawing::Image **bmp;

I get this error message:
error C3160: 'bmp' : cannot declare interior __gc pointer or reference as amember of 'RCClientNS::RCClientComm'.

What is the solution?

Thank's alot,
Itay.


--

This posting is provided "AS IS" with no warranties, and confers no

rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they
originated.

Nov 16 '05 #3
Sorry I misread your original post. It seems the 2nd level of indirection must be a __nogc* pointer. This compiles:

__gc class ImgPtr{
public:
System::Drawing::Image* __nogc* ppBmp;
};

int _tmain(){
ImgPtr* iptr = new ImgPtr;
*(iptr->ppBmp) = new System::Drawing::Bitmap(640, 480);
}

For more info, check out section 7.4 of the Managed Extensions for C++ Spec (Visual Studio help).
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vcmxspec/html/vcManagedExtensionsSpec_7_4.htm

Adam Mitz
Microsoft
--------------------
Reply-To: "Itay_k" <it****@walla.co.il>
From: "Itay_k" <it****@walla.co.il>
References: <##**************@TK2MSFTNGP10.phx.gbl> <Fb**************@cpmsftngxa06.phx.gbl>
Subject: Re: pointer to pointer to a managed class
Date: Tue, 29 Jul 2003 22:12:47 +0200
Lines: 104
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <#W**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: 80.178.1.14.forward.012.net.il 80.178.1.14
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26653
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

Thanks you, but my class is managed.
I need to add this member (pointer to pointer) to a managed class, so why it
isn't working?

Itay.


"Adam Mitz [MSFT]" <t-****@microsoft.com> wrote in message
news:Fb**************@cpmsftngxa06.phx.gbl...
Use the provided (in vcclr.h) template gcroot<T> as the member of the

unmanaged class. This allows the garbage collector to track the reference
to the
managed object (so it can be updated if/when the GC decides to move the

object).
See an example below.

Adam Mitz
Microsoft

#include <vcclr.h>
#using <mscorlib.dll>

using namespace System;

__nogc class UM{
public:
gcroot<Object*> ptr;
};

__gc class M{
public:
String* data;
void SetData(String* in_data){
data = in_data;
}
String* ToString(){
return data;
}
};

int _tmain()
{
M* m = new M;
m->SetData(S"Hello World!");
UM um;
um.ptr = m;
Console::WriteLine(um.ptr->ToString());
return 0;
}
--------------------
>Reply-To: "Itay_k" <it****@walla.co.il>
>From: "Itay_k" <it****@walla.co.il>
>Subject: pointer to pointer to a managed class
>Date: Mon, 28 Jul 2003 13:35:13 +0200
>Lines: 18
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.3790.0
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Message-ID: <##**************@TK2MSFTNGP10.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vc
>NNTP-Posting-Host: 80.178.8.240.forward.012.net.il 80.178.8.240
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26587
>X-Tomcat-NG: microsoft.public.dotnet.languages.vc
>
>Hello,
>
>I want a member in my class that will save pointer to pointer to
>System::Drawing::Image class.
>When I write on my class code:
>
>System::Drawing::Image **bmp;
>
>I get this error message:
>error C3160: 'bmp' : cannot declare interior __gc pointer or reference asa >member of 'RCClientNS::RCClientComm'.
>
>What is the solution?
>
>Thank's alot,
>Itay.
>
>
>

--

This posting is provided "AS IS" with no warranties, and confers no

rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this

message are best directed to the newsgroup/thread from which they
originated.


--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Nov 16 '05 #4
While looking at the provided example question arises - is the reverse
possibel (to have/store/use a pointer to the unmanaged class in the managed
one)???

"Adam Mitz [MSFT]" <t-****@microsoft.com> wrote in message
news:Fb**************@cpmsftngxa06.phx.gbl...
Use the provided (in vcclr.h) template gcroot<T> as the member of the unmanaged class. This allows the garbage collector to track the reference
to the managed object (so it can be updated if/when the GC decides to move the object). See an example below.

Adam Mitz
Microsoft

#include <vcclr.h>
#using <mscorlib.dll>

using namespace System;

__nogc class UM{
public:
gcroot<Object*> ptr;
};

__gc class M{
public:
String* data;
void SetData(String* in_data){
data = in_data;
}
String* ToString(){
return data;
}
};

int _tmain()
{
M* m = new M;
m->SetData(S"Hello World!");
UM um;
um.ptr = m;
Console::WriteLine(um.ptr->ToString());
return 0;
}
--------------------
Reply-To: "Itay_k" <it****@walla.co.il>
From: "Itay_k" <it****@walla.co.il>
Subject: pointer to pointer to a managed class
Date: Mon, 28 Jul 2003 13:35:13 +0200
Lines: 18
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <##**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: 80.178.8.240.forward.012.net.il 80.178.8.240
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26587
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

Hello,

I want a member in my class that will save pointer to pointer to
System::Drawing::Image class.
When I write on my class code:

System::Drawing::Image **bmp;

I get this error message:
error C3160: 'bmp' : cannot declare interior __gc pointer or reference as amember of 'RCClientNS::RCClientComm'.

What is the solution?

Thank's alot,
Itay.


--

This posting is provided "AS IS" with no warranties, and confers no

rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they
originated.

Nov 16 '05 #5
Adam Mitz [MSFT] wrote:
Sorry I misread your original post. It seems the 2nd level of
indirection must be a __nogc* pointer. This compiles:

__gc class ImgPtr{
public:
System::Drawing::Image* __nogc* ppBmp;
};

int _tmain(){
ImgPtr* iptr = new ImgPtr;
*(iptr->ppBmp) = new System::Drawing::Bitmap(640, 480);
}


Of course, keep in mind that __nogc pointers to managed objects or other
__gc pointers is inherently dangerous. In order to ensure that the __nogc
pointer points to a valid object, the object it points to must be pinned. As
pinning can only be done by __pin pointers, which can only exist on the
stack, it is a really bad idea to store a __nogc pointer that points to a
managed object in a class or someother static or dynamic storage.

Rather than looking for a way to store a pointer to a pointer to a managed
class, I'd step back and ask why you want to do that? To do this correctly
with the CLR is a lot of work, and it will likely be better to just
rearchitect the program to avoid this necessity.

Cheerio!

--
Brandon Bray Visual C++ Compiler
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #6
Yes. Managed classes can have pointers to unmanaged classes as members. No special syntax is required.
--------------------
From: "Vadym Stetsyak" <va*****@ukr.net>
Subject: Re: pointer to pointer to a managed class
Date: Wed, 30 Jul 2003 22:20:43 +0300

While looking at the provided example question arises - is the reverse
possibel (to have/store/use a pointer to the unmanaged class in the managed
one)???

"Adam Mitz [MSFT]" <t-****@microsoft.com> wrote in message
news:Fb**************@cpmsftngxa06.phx.gbl...
Use the provided (in vcclr.h) template gcroot<T> as the member of the

unmanaged class. This allows the garbage collector to track the reference
to the
managed object (so it can be updated if/when the GC decides to move the

object).
See an example below.

Adam Mitz
Microsoft

#include <vcclr.h>
#using <mscorlib.dll>

using namespace System;

__nogc class UM{
public:
gcroot<Object*> ptr;
};

__gc class M{
public:
String* data;
void SetData(String* in_data){
data = in_data;
}
String* ToString(){
return data;
}
};

int _tmain()
{
M* m = new M;
m->SetData(S"Hello World!");
UM um;
um.ptr = m;
Console::WriteLine(um.ptr->ToString());
return 0;
}
--------------------
>Reply-To: "Itay_k" <it****@walla.co.il>
>From: "Itay_k" <it****@walla.co.il>
>Subject: pointer to pointer to a managed class
>Date: Mon, 28 Jul 2003 13:35:13 +0200
>Lines: 18
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.3790.0
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Message-ID: <##**************@TK2MSFTNGP10.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vc
>NNTP-Posting-Host: 80.178.8.240.forward.012.net.il 80.178.8.240
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26587
>X-Tomcat-NG: microsoft.public.dotnet.languages.vc
>
>Hello,
>
>I want a member in my class that will save pointer to pointer to
>System::Drawing::Image class.
>When I write on my class code:
>
>System::Drawing::Image **bmp;
>
>I get this error message:
>error C3160: 'bmp' : cannot declare interior __gc pointer or reference asa >member of 'RCClientNS::RCClientComm'.
>
>What is the solution?
>
>Thank's alot,
>Itay.
>
>
>

--

This posting is provided "AS IS" with no warranties, and confers no

rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this

message are best directed to the newsgroup/thread from which they
originated.


--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Nov 16 '05 #7

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

Similar topics

0
by: DotNetJunkies User | last post by:
Background: I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below: Range r = new Range( 2, 2 ); r = new Cell( “Hello Mum” ); Range is a...
6
by: Peter Oliphant | last post by:
Here is a simplification of my code. Basically, I have a class (A) that can be constructed using a function pointer to a function that returns a bool with no parameters. I then want to create an...
4
by: Maxwell | last post by:
Hello, Newbie question here for disposing of unmanaged resources in MC++.NET. I have a managed VS.NET 2003 MC++ wrapper class that wraps a unmanaged C++ dll. What I am trying to figure out is...
2
by: T Ray Humphrey | last post by:
I could not get the following code to compile: public ref class wrapper { void Read(int^ mpLen) { pin_ptr<int> pLen = mpLen; unmanaged* punman = new unmanaged(); punman->Read(pLen); return; }
0
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to...
7
by: Russell Mangel | last post by:
/* Hi, I am trying to hold a reference to un-managed pointer IStorage. The client/callers will make many accesses to IStorage, but only in-directly. For performance reasons IStorage needs to...
3
by: vijay.gandhi | last post by:
Hi, I am trying to convert some unmanaged code (C++) to managed code (using C++/CLI). 1) One of the functions used returns a void* which I need to cast into a handle of a managed object. Can...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.