-
November 15th, 2001, 04:38 PM
#1
GetLastError() return 1
if (!WaitCommEvent(hComm,&dwEvent,&os))
{
if (lrc = GetLastError() == ERROR_IO_PENDING)
{
GetOverlappedResult(hComm,&os,&nBytesRead,TRUE);
}
}
GetLastError() returns 1 which is:
1 Incorrect function. ERROR_INVALID_FUNCTION
This loop runs fine the first time but give this error in 2nd interation. What do I need to look into!?
Thanks
-
November 15th, 2001, 04:47 PM
#2
Re: GetLastError() return 1
Check to see if the hComm handle still holds the right value, maybe it got overwritten. Are you sure the hComm handle is still valid (it hasn't been closed at the 2nd time round).
-
November 15th, 2001, 05:21 PM
#3
Re: GetLastError() return 1
What OS are you using ?
AFAIK GetLastError is useless under Windows 95/98
(don't know about Windows ME).
If you are using Windows NT/2000/XP, just ignore this post.
Best regards,
Matthias.
~ Excuse my bad english. I'm drunk and I'm german. ~
-
November 15th, 2001, 05:42 PM
#4
Re: GetLastError() return 1
hi,
the hComm handle is valid and correct. I suspect something wrong with the OVERLAPPED mode parameters !?
Its Win2000
Thanks
-
November 15th, 2001, 06:10 PM
#5
Re: GetLastError() return 1
Try adding a couple of Parentheses to your function. GetLastError is probably returning ERROR_IO_PENDING and lrc is being set TRUE
if (!WaitCommEvent(hComm,&dwEvent,&os))
{
if ((lrc = GetLastError()) == ERROR_IO_PENDING)
{
GetOverlappedResult(hComm,&os,&nBytesRead,TRUE);
}
}
-
November 15th, 2001, 06:38 PM
#6
GetLastError() is okay now but...
Thanks This is taken care of! but I have another problem.
In the above code, nBytesRead is always 4 after GetOverlappedResult() returns! More interestingly in first iteration GetOverlap.. properly waits for the event to come. When it recieve something it always returns with nBytesRead = 4! I am checking the bytes on port immediatly afterwords.
ClearCommError(hComm,&dwErrorMask,&comstat);
nToRead = comstat.cbInQue;
cbInQue always contain different number than 4! In the 2nd iteration, this function doesn't even wait but cbInQue is zero afterwords. If there is no byte recieved, why was the event fired! In the third iteration it still again goes on proper wait.
Following is the event mask.
SetCommMask(hComm,EV_RXCHAR);
What am I doing wrong. Lots of things?
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|