GetLastError() return 1
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: GetLastError() return 1

  1. #1
    Join Date
    Jan 2001
    Posts
    306

    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


  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,100

    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).


  3. #3
    Join Date
    Oct 1999
    Location
    Germany
    Posts
    238

    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. ~

  4. #4
    Join Date
    Jan 2001
    Posts
    306

    Re: GetLastError() return 1

    hi,
    the hComm handle is valid and correct. I suspect something wrong with the OVERLAPPED mode parameters !?

    Its Win2000

    Thanks


  5. #5
    Join Date
    May 1999
    Location
    Albuquerque, NM
    Posts
    304

    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);
    }

    }





  6. #6
    Join Date
    Jan 2001
    Posts
    306

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center