title: managed system.timer over un managed code
body: <p>New to the groups, sorry if this the wrong forum/etiquette. I am coding
  a c++ application that requires the use of a timer-triggered event
  handler. I decided to use the timer provided in System::Timers::Timer.
  My understanding of the next part is not very good, as my code may
  reveal, but as I understand it, my application is "unmanaged C++",
  whereas the timer extension from the system DLL is managed. Therefore I
  needed to use the gcroot template to allow the inclusion of the
  "managed" timer code.</p>
  
  <pre><code>#include &lt;vcclr.h&gt;
  
  #using &lt;mscorlib.dll&gt;
  using namespace System;
  
  #using &lt;System.dll&gt;
  using namespace System::Timers;
  
  class DataStream
  {
     public:
     DataStream():m_N(48),m_saving(false)
     {
        // set up the window timer
        m_Timer = gcnew Timer;
        m_Timer-&gt;Elapsed += gcnew
        ElapsedEventHandler(DataStream::nextCandle);
        m_Timer-&gt;Interval= CANDLE_DURATION * 1000;
        m_Timer-&gt;AutoReset= true;
        m_Timer-&gt;Enabled=true;
      }; // default constructor
  
  private:
     gcroot&lt;Timer^&gt; m_Timer; /* use gcroot because can't use managed object in unmanaged class. */
  
     void nextCandle(Object ^sender, ElapsedEventArgs ^e);
  
  };
  
  void DataStream::nextCandle(Object ^sender/*source*/, ElapsedEventArgs ^e/*e*/)
  {
     // do some stuff ...
  }
  </code></pre>
  
  <p>Here's the problem, upon compilation, I get this error:</p>
  
  <pre><code>Compiling...
  dataStream.cpp
  c:\blah\dataStream.h(18) : error C3867: 'DataStream::nextCandle':
  function call missing argument list; use '&amp;DataStream::nextCandle' to
  create a pointer to member
  c:\blah\dataStream.h(18) : error C3350:
  'System::Timers::ElapsedEventHandler' : a delegate constructor expects
  2 argument(s)
  </code></pre>
  
  <p>At first, I didn't include the &amp; reference suggested by the compiler
  because most examples I had seen do not use this.</p>
  
  <p>Upon inclusion, changing:</p>
  
  <pre><code>m_Timer-&gt;Elapsed += gcnew ElapsedEventHandler(DataStream::nextCandle);
  </code></pre>
  
  <p>to....</p>
  
  <pre><code>m_Timer-&gt;Elapsed += gcnew ElapsedEventHandler(&amp;DataStream::nextCandle);
  </code></pre>
  
  <p>I get the following error on compilation:</p>
  
  <pre><code>c:\blah\dataStream.h(18) : error C3364:
  'System::Timers::ElapsedEventHandler' : invalid argument for delegate
  constructor; delegate target needs to be a pointer to a member function
  </code></pre>
  
  <p>So I'm stuck at this point. I'm not sure if the solution is a few small
  changes away from where I am, or if these errors are indicative of a
  larger problem (i.e. me using the gcroot template and mixing managed
  and unmanaged code with zero experience in that). I'm using Visual C++ Express Edition Beta.</p>