473,387 Members | 1,569 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,387 software developers and data experts.

auto_ptr in managed code

How do I use auto_ptr in managed C++?

Here is my existing code:

namespace Alta
{
public __gc class CMDAQ
{
public:
CMDAQ();
~CMDAQ();
private:
CDAQControl* itsDAQControl;
};
}

namespace Alta
{
CMDAQ::CMDAQ( )
{
itsDAQControl = new CDAQControl();
}

CMDAQ::~CMDAQ()
{
delete itsDAQControl;
}
}

If I change this code to the following, I get "error C3633: cannot define
itsDAQControl as a member of managed Alta::CMDAQ"

namespace Alta
{
public __gc class CMDAQ
{
public:
CMDAQ();
~CMDAQ();
private:
std::auto_ptr< CDAQControl > itsDAQControl;
};
}

namespace Alta
{
CMDAQ::CMDAQ( )
{
std::auto_ptr< CDAQControl > dc( new CDAQControl() );
itsDAQControl = dc;
}

CMDAQ::~CMDAQ()
{
}
}

thanks

Bill
Nov 16 '05 #1
5 1685
Bill Burris wrote:
How do I use auto_ptr in managed C++?

[SNIP]

If I change this code to the following, I get "error C3633: cannot define
itsDAQControl as a member of managed Alta::CMDAQ"
...
private:
std::auto_ptr< CDAQControl > itsDAQControl;


Hi Bill,
Unfortunately, you cannot do this with the current C++ language. auto_ptr
is a native class, and it is not possible to embed that class in a __gc
class. I realize this is a burden, and believe me -- we are working to
improve this situation.

The next version of the Visual C++ will allow you to write a different
auto_ptr template that would achieve what you are trying to do.

Cheerio!

--
Brandon Bray Visual C++ Compiler
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #2

"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
auto_ptr
is a native class, and it is not possible to embed that class in a __gc
class. I realize this is a burden, and believe me -- we are working to
improve this situation.


What other native classes are not usable in a _gc class?

I use managed C++ as the bridge between my native C++ code and C#. If I was
doing pure .NET code, I would use C#.

Bill
Nov 16 '05 #3
Bill Burris wrote:
What other native classes are not usable in a _gc class?
With one exception, all native classes cannot be embedded in a __gc class.
The exception is POD types (a POD is short for "plain old data" and is a
class that neither has a user defined copy constructor nor a user defined
destructor, and contains only other PODs or scalar data).
I use managed C++ as the bridge between my native C++ code and C#. If I
was doing pure .NET code, I would use C#.


I understand your position. This too is a sentiment we are looking to fix in
the next version of Visual C++.

Cheerio!

--
Brandon Bray Visual C++ Compiler
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #4
"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...

With one exception, all native classes cannot be embedded in a __gc class.
The exception is POD types (a POD is short for "plain old data" and is a
class that neither has a user defined copy constructor nor a user defined
destructor, and contains only other PODs or scalar data).


I have been using destructors in my managed C++. It seems to work ok.

Some __gc code which uses native classes:

CMDAQ::CMDAQ( IMessageHandler* pMessageHandler, int siteId, int
interfaceType )
{
itsMessageDispatcher = new CMessageDispatcher();
itsMessageDispatcher->itsMessageHandler = pMessageHandler;
CDebug::Initialize( itsMessageDispatcher );
try
{
itsDAQControl = new CDAQControl( itsMessageDispatcher, siteId,
interfaceType );
itsHistogramGroup = itsDAQControl->GetHistogramGroup();
itsPhantomHistogramGroup = itsDAQControl->GetPhantomHistogramGroup();
}
catch( char* str )
{
itsMessageDispatcher->DebugMessage( str );
throw( new System::Exception( str ) );
}
}

CMDAQ::~CMDAQ()
{
delete itsDAQControl;
delete itsMessageDispatcher;
}

This is used in my C# code as follows:

public class DAQ
{
private static CMDAQ itsDaq = null;
private IMessageHandler itsMessageHandler;

public DAQ( IMessageHandler messageHandler, int interfaceType, int
siteId )
{
itsMessageHandler = messageHandler;
itsDaq = new CMDAQ( itsMessageHandler, siteId, interfaceType );
}

public void Dispose()
{
itsDaq.__dtor();
}

Dispose is called in the OnClosing funtion for my Form:

protected override void OnClosing( CancelEventArgs e )
{
base.OnClosing( e );
if( itsState == ProgState.DAQ )
{
itsDaq.Stop();
itsDaq.Dispose();
itsSettings.Save( @"c:\alta_prog\33\ProgramSettings.xml" );
}
}

Bill
Nov 16 '05 #5
"Brandon Bray [MSFT]" <br******@online.microsoft.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
Bill Burris wrote:
I use managed C++ as the bridge between my native C++ code and C#. If I
was doing pure .NET code, I would use C#.
I understand your position. This too is a sentiment we are looking to fix

in the next version of Visual C++.


Even better would be if I could do everything in C#. For that to happen I
need serial port support in .NET, or device drivers for Motorola GPS
receivers which are usable in .NET. Also Measurement Computing
http://www.measurementcomputing.com/, hardware needs to be accessible from
..NET, and a .NET version of Tetradyne DriverX
http://www.tetradyne.com/driverx.htm.

Support for USB would also come in handy. I tried to roll my own but didn't
get very far. What I did do is posted at
http://www.componentsnotebook.com/no.../deviceio.aspx.

Bill
Nov 16 '05 #6

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

Similar topics

6
by: Noah Roberts | last post by:
Often I have a method which accepts a pointer to some class as an argument. Usually that pointer is managed by the caller through std::auto_ptr. I would assume that you could pass the auto_ptr in...
45
by: Jamie Burns | last post by:
Hello, I realise that I just dont get this, but I cannot see the need for auto_ptr. As far as I have read, it means that if you create an object using an auto_ptr, instead of a raw pointer, then...
4
by: Kurt Stutsman | last post by:
I am developing a type that protects ownership of data with non-const ref copy-constructor and assignment operator similiar to auto_ptr<>. I read that auto_ptr<> uses auto_ptr_ref to fascilitate...
6
by: Jon | last post by:
Is auto_ptr allowed in managed C++ class? I have my doubts because of the following example: #include "stdafx.h" #include <iostream> #include <memory> using namespace std; #using...
8
by: Lloyd Dupont | last post by:
I try to use the auto_ptr in my code but that doesn't work. even std::auto_ptr. I guess I have to add an #include statement, but I can't figure out the right file to add. Also I want to use...
9
by: dragoncoder | last post by:
Hi all, I am trying to understand the auto_ptr_ref role in the implementation of auto_ptr<>. I read the information on net but still not 100% sure of it. My plan is as follows. 1. To see the...
39
by: Andre Siqueira | last post by:
Hello all, I have a member function like thist: Query(const std::string & id, std::auto_ptr<Modifiermodif = std::auto_ptr<Modifier>()) when a try to instantiate a Query like ...
7
by: j.l.olsson | last post by:
Hello, I am using std::auto_ptr to try to keep ownership of resources straight. However, I became aware that exception objects must provide a copy constructor, which made me uncertain of the...
17
by: Ankur Arora | last post by:
Hi All, I'm building a sample application that uses a custom auto_ptr implementation. The program crashes with the following output:- Output (Debug Assertion failed) ----------
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.