First Arduino-C++ Crossover

Hello, I'm very new to the Arduino world and I just bought my first Duemilanove. I asked a similar question before but I realize that I was being very unclear in my wording and would like to start again asking more specific questions.

I am proficient in C++ and have learned how to program the Arduino, but now I am trying to have a C++ terminal window display everything that the Arduino is outputting. I will later change the C++ code to calculate and process based on the data. My current code in the Arduino sketch is:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.println("Hello World");
  delay(1000);
}

I am using the functions provided by the files on this pagehttp://www.arduino.cc/playground/Interfacing/CPPWindows. I seem to be having trouble implementing the code, it compiles but it does not properly connect to the Arduino and I get a status=-1 error over and over. I want the C++ window to display "Hello World" every time the Arduino outputs it. Could anyone write up a quick implementation of the code? I assume it would just be running three or four functions sequentially, but I can't seem to get it right. All help is much appreciated!

After ReadData, do this:

DWORD dwResult = GetLastError();
printf("ERROR: Read Failed. Reason: %8.8X.\n", dwResult);

What is dwResult in your sample? -1 in the return means that either the number of bytes you are asking for isn't yet available, or there was an error reading from the device. That number can be looked up on MSDN to determine the error.

However, also be sure that the constructor worked and actually opened the port. I don't like the sample in that the Serial constructor actually has a chance to fail in that example class, yet throws no exceptions to indicate failure.

To check the open worked, add a Serial function in Serial.h :

bool IsOpen() { return (this->hSerial != INVALID_HANDLE_VALUE);};

And, after you use

Serial SerialPort("COM4")

in your code, check to see if the port is open before calling ReadData like this:

if(!SerialPort.IsOpen())
{
   printf("Failed to open.");
}