GetLastError() random errors

This is a discussion on GetLastError() random errors within the Windows Programming forums, part of the Platform Specific Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    108

    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?

    cheers

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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."
    -XSquared

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    Hello,

    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
    Posts
    2,544
    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
    Posts
    108
    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, 04: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, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21