Hi

I am use to using the old c/c++ system("dir") in the 16-bit world. how do I use it in the vc++ express 2008 world?

Thanks

Recommended Answers

All 5 Replies

the same way.

system("dir");

I am confused...

in vc++ all I need to do is use system("dir"); ??

Pretty much.

But you need to post your actual code and better observations than "it doesn't work" for a better response.

I need an example of how to write a Windows Service that output the time and list of files in that directory every 2 mins. I am using Visual Studio 2003 and am a c++ coder. I am just wanting to learn to use VC++.. So I am need a little guidance on what to do...

Thanks

Mike

Hi ...

I am feeling more like a newbie with VC++, so forgive me.. Here is some code I am using as a timer I got off the web.

#using <system.dll>

using namespace System;
using namespace System::Timers;

public ref class Timer1
{
private: 
   static System::Timers::Timer^ aTimer;

public:
   static void Demo()
   {
      // Normally, the timer is declared at the class level,
      // so that it stays in scope as long as it is needed.
      // If the timer is declared in a long-running method,  
      // KeepAlive must be used to prevent the JIT compiler 
      // from allowing aggressive garbage collection to occur 
      // before the method ends. (See end of method.)
      //System::Timers::Timer^ aTimer;

      // Create a new Timer with Interval set to 10 seconds.
      aTimer = gcnew System::Timers::Timer( 10000 );

      // Hook up the Elapsed event for the timer.
      aTimer->Elapsed += gcnew ElapsedEventHandler( Timer1::OnTimedEvent );

      // Set the Interval to 2 seconds (4000 milliseconds).
      aTimer->Interval = 4000;
      aTimer->Enabled = true;

      Console::WriteLine("Press the Enter key to exit the program.");
      Console::ReadLine();

      // If the timer is declared in a long-running method, use
      // KeepAlive to prevent garbage collection from occurring
      // before the method ends.
      GC::KeepAlive(aTimer);
   }


private:
   // Specify what you want to happen when the Elapsed event is 
   // raised.
   static void OnTimedEvent( Object^ source, ElapsedEventArgs^ e )
   {
      Console::WriteLine( "The Elapsed event was raised at {0}", e->SignalTime );
   }

};

int main()
{
   Timer1::Demo();
  
}

/* This code example produces output similar to the following:

Press the Enter key to exit the program.
The Elapsed event was raised at 5/20/2007 8:42:27 PM
The Elapsed event was raised at 5/20/2007 8:42:29 PM
The Elapsed event was raised at 5/20/2007 8:42:31 PM
...
*/

Now what I want to do is this. I want to make a system call to list directory every 10 seconds. Then I also want to know where to go to read about doing read and writing files. I suppose iostream is passe now.

Sorry for being so dumb on this one.. examples do help me

One last question.. I still need to understand how to make this a windows service?

Thanks

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.