Thread: GetLastError() random errors

  1. #1
    Registered User
    Join Date
    Jan 2005

    GetLastError() random errors

    Hello all,

    is it normal for GetLastError() to continually return 2 (ERROR_FILE_NOT_FOUND) and 5 (ERROR_ACCESS_DENIED), when you call them?

    I mean, I tried GetLastError() at the beginning of WinMain(), and it returns 2. And then in some other places GetLastError() returns 5, but then I'm pretty sure the crashes that have been happening in my program isn't because of file accesses.

    Unless error 5 (ERROR_ACCESS_DENIED) means memory access?

    Anybody has any ideas?


  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    Just yesterday, I think I had a function fail and GetLastError returned 2, but it had nothing to do with "FILE_NOT_FOUND" (I don't recall what the problem was exactly...)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  3. #3
    Registered User
    Join Date
    Jan 2005

    I fixed my problem, it was to do with not mallocing the proper amount. but yeah, I still don't get what the GetLastError() messages really means.

    thanks for the reply though, now I know it's not just me

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    You can only rely on the return value of GetLastError when:
    • You have just called a WinAPI function (there can be no calls to other functions in between the original call and the call to GetLastError).
    • The return value of the function indicates it has failed.
    • The function is documented to provide a GetLastError value.

    At other times, the GetLastError value is not useful.

  5. #5
    Registered User
    Join Date
    Jan 2005
    I see, thanks for the info

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM