std C++ objects in Managed memory

J

Jeremy Cowles

Is it possible to pass an instance of a standard C++ class into managed
memory and use it (MC++/C#/VB/J#)? I guess I am still foggy on the whole
concept of Managed C++.

TIA,
Jeremy
 
A

Adam Mitz [MSFT]

You can provide a proxy managed class to wrap the native class. I've done a short example below. Also see
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vcmxspec/html/vcmg_overview.htm
in the VS help system.

Adam Mitz
Microsoft

class UnManaged{
public:
int data;
UnManaged(int d = 0) : data(d) {
}
};

__gc class Managed{
public:
UnManaged& um;
Managed() : um(*new UnManaged){
}
~Managed(){
delete &um;
}
__property int get_data(){
return um.data;
}
__property void set_data(int d){
um.data = d;
}
};

int _tmain()
{
Managed* m = new Managed;
m->data = 23;
Console::WriteLine(m->data.ToString());
}
--------------------
From: "Jeremy Cowles" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vc
Subject: std C++ objects in Managed memory
Lines: 7
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Date: Tue, 15 Jul 2003 19:41:25 GMT
NNTP-Posting-Host: 24.92.196.40
X-Complaints-To: (e-mail address removed)
X-Trace: twister.tampabay.rr.com 1058298085 24.92.196.40 (Tue, 15 Jul 2003 15:41:25 EDT)
NNTP-Posting-Date: Tue, 15 Jul 2003 15:41:25 EDT
Organization: RoadRunner - Tampa Bay
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.frii.net! newsfeed.frii.net!news-out.newsfeeds.com!propagator2-maxim!news-in.superfeed.net!news-west.rr.com!news.rr.com!cyclone.tampabay.rr.com!news-
post.tampabay.rr.com!twister.tampabay.rr.com.POSTED!53ab2750!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26204
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

Is it possible to pass an instance of a standard C++ class into managed
memory and use it (MC++/C#/VB/J#)? I guess I am still foggy on the whole
concept of Managed C++.

TIA,
Jeremy


--

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top