read data from serial monitor to Computer ?

Hi, I'm trying to read the data from the serial monitor and then store it into a file. I use the code in the following link
http://playground.arduino.cc/Interfacing/CPPWindows

When I run, the error "ERROR!!!" occurred. I checked the code and it's an error in INVALID_HANDLE_VALUE, however i dont know why and how to fix it ?

I used Seeeduino ADK Atmega2560, COM8, with baudrate 9600.

Can someone help me ?
Thanks

In: CreateFile(portName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
Are you sure that file exist? You try to open a file with dwCreationDisposition set to OPEN_EXISTING. If the file dosn’t exist you will get an error. Instedat you can use OPEN_ALWAYS.

Thanks @jkj56 . I found the error and got it working now.