auto_ptr in managed code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Burris

    #1

    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


  • Brandon Bray [MSFT]

    #2
    Re: auto_ptr in managed code

    Bill Burris wrote:[color=blue]
    > 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;[/color]

    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.


    Comment

    • Bill Burris

      #3
      Re: auto_ptr in managed code


      "Brandon Bray [MSFT]" <branbray@onlin e.microsoft.com > wrote in message
      news:OjjrWYyfDH A.2344@TK2MSFTN GP10.phx.gbl...
      [color=blue]
      > 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.[/color]

      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


      Comment

      • Brandon Bray [MSFT]

        #4
        Re: auto_ptr in managed code

        Bill Burris wrote:[color=blue]
        > What other native classes are not usable in a _gc class?[/color]

        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).
        [color=blue]
        > 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#.[/color]

        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.


        Comment

        • Bill Burris

          #5
          C++ destructor in MC++ Re: auto_ptr in managed code

          "Brandon Bray [MSFT]" <branbray@onlin e.microsoft.com > wrote in message
          news:uTSmSCXhDH A.4088@tk2msftn gp13.phx.gbl...[color=blue]
          >
          > 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).
          >[/color]

          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 )
          {
          itsMessageDispa tcher = new CMessageDispatc her();
          itsMessageDispa tcher->itsMessageHand ler = pMessageHandler ;
          CDebug::Initial ize( itsMessageDispa tcher );
          try
          {
          itsDAQControl = new CDAQControl( itsMessageDispa tcher, siteId,
          interfaceType );
          itsHistogramGro up = itsDAQControl->GetHistogramGr oup();
          itsPhantomHisto gramGroup = itsDAQControl->GetPhantomHist ogramGroup();
          }
          catch( char* str )
          {
          itsMessageDispa tcher->DebugMessage ( str );
          throw( new System::Excepti on( str ) );
          }
          }

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

          This is used in my C# code as follows:

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

          public DAQ( IMessageHandler messageHandler, int interfaceType, int
          siteId )
          {
          itsMessageHandl er = messageHandler;
          itsDaq = new CMDAQ( itsMessageHandl er, 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.Sav e( @"c:\alta_prog\ 33\ProgramSetti ngs.xml" );
          }
          }

          Bill


          Comment

          • Bill Burris

            #6
            more I/O support is needed in .NET Re: auto_ptr in managed code

            "Brandon Bray [MSFT]" <branbray@onlin e.microsoft.com > wrote in message
            news:uTSmSCXhDH A.4088@tk2msftn gp13.phx.gbl...[color=blue]
            > Bill Burris wrote:[color=green]
            > > 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#.[/color]
            >
            > I understand your position. This too is a sentiment we are looking to fix[/color]
            in[color=blue]
            > the next version of Visual C++.[/color]

            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


            Comment

            Working...