Help with how to read/write to COM port in VC++.NET

I was wondering if someone could tell me why my code will not read from a COM port successfully. My output window says that no bytes have been read. I have attached my code below. Thanks!

#include "stdafx.h"
#include "windows.h"

#using <mscorlib.dll>

using namespace System;

int _tmain()
{
HANDLE hSerial;
BOOL w_ret;
BOOL r_ret;
hSerial = CreateFile("COM1",GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hSerial==INVALID_HANDLE_VALUE){
if(GetLastError()==ERROR_FILE_NOT_FOUND){
printf("COM port not found!\n\n");
}
printf("Error opening COM port!\n\n");
}
DCB dcbSerialParams = {0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams))
printf("Error getting state!\n\n");

dcbSerialParams.BaudRate=CBR_19200;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;

if(!SetCommState(hSerial, &dcbSerialParams))
printf("Error setting states!\n\n");

COMMTIMEOUTS cto = {MAXDWORD, 0, 0, 0, 0 };
//COMMTIMEOUTS cto = {50, 50, 10, 50, 10};
//COMMTIMEOUTS cto = { 1, 100, 1000, 0, 0 };
if (!SetCommTimeouts(hSerial, &cto))
printf("Error setting timeouts!\n\n"); // Error setting time-outs.

bool success = PurgeComm(hSerial, PURGE_TXABORT | PURGE_RXABORT |PURGE_TXCLEAR | PURGE_RXCLEAR );// purge any information in the buff
printf("Print '1' if purge was completed: %d\n\n", success); //check bool success to see if function was performed correctly
//FlushFileBuffers(hSerial); //clear buffers


DWORD write=19; // Number of bytes to write to serial port
char buf[20]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}; // Decmial value to write to serial port
w_ret = WriteFile(hSerial,buf,write,&write,NULL); // write is updated with the number of bytes written
printf("The number of bytes written was %d\n\n", write);

if (w_ret) //check to see if Write function was performed correctly
printf("Written....\n\n");
else
printf("Error writing!\n\n");
for(int y=0; y<write; y++)
printf("%d ", bufYes);
char szBuff[128] = {0};
DWORD dwBytesRead = 0;
printf("\n\nAt least its about to read....\n\n");
r_ret = ReadFile(hSerial, szBuff, 127, &dwBytesRead, NULL);
if (r_ret) //check to see if Read function was performed correctly
printf("Reading...\n\n");
else
printf("Error reading!\n\n");

printf("The number of bytes read was %d\n\n", dwBytesRead);
int i=0;
while(i<dwBytesRead) {
printf("%d ", szBuffIdea);
i++;
}

CloseHandle(hSerial);
char lastError[1024];
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
lastError,
1024,
NULL);
printf("done\n\n");

return 0;
}

[3414 byte] By [shdjsm] at [2007-12-20]
# 1

This forum is for C++ language issues, not Win32 programming questions. I would ask this question here:

http://msdn.microsoft.com/newsgroups/topic.aspx?url=/MSDN-FILES/028/201/015/topic.xml

BrianKramer at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...