Serial Comm. in VC++4.0 ie ReadFile etc..

When writing to and reading from COM2
using GetComm...SetComm...WriteFile...
ReadFile and so on, my ReadFile func.
is returning error #87. Although it's
not a guarantee, I am assuming this is
an invalid parameter error(Error Codes
in on-line help). The following is my
handle initialization:
hCom=CreateFile("COM2",GENERIC_READ |
GENERIC_WRITE,0,NULL,OPEN_EXISTING,
0,NULL); I can write to the port with
no problem, I know my CommState is
correct. My error is a run-time error
when the ReadFile is attempted. My read
statement is: BOOL rSuccess = ReadFile(hCom,
&data,nBytesToRead,&nBytesRead,NULL).
&data is LPVOID, nB..T..R is DWORD,
&nB..R is LPDWORD, and I am not using
OVERLAPPED operations.
What am I doing wrong??????? As a test
I continuously send one byte 0xff of data
until I receive that data back from another
program which is monitoring COM2. I have
another PC that is watching this
communication and displaying the data that
is sent and received. This PC can see the
0xff sent and 0xff received, but the ReadFile
function is not reading the 0xff. I am not
using any timeout functions. The write func
ends after 1024 attempts for a successful
read.
Is there any other Communications functions
that may be better for me to use? Eventually
I will be using the WaitCommEvent function
to monitor for interrupt messages. Right now
I really need to know why the ReadFile is
not working properly.
LVL 2
jrmcgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Try this:

BYTE data[8];
DWORD dwBytesRead;
BOOL rSuccess = ReadFile(hCom, data, 1, &dwBytesRead, NULL);


/*lpNumberOfBytesRead

Points to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking.*/

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.