CreateFile returns err 5 on 2000, but works fine of XP

This is a discussion on CreateFile returns err 5 on 2000, but works fine of XP within the Windows Programming forums, part of the Platform Specific Boards category; Originally Posted by maxorator Let me correct you. Open source or shared code shouldn't use magic numbers. Let me correct ...

  1. #16
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by maxorator View Post
    Let me correct you. Open source or shared code shouldn't use magic numbers.
    Let me correct *you*. I've inherited a lot of code in my time, and I still get that will to strangle people who leave me with poorly written code. You should always assume that your code will be looked after by someone else.... and that that someone else can find out where you live... you've been warned

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  2. #17
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by QuantumPete View Post
    Let me correct *you*. I've inherited a lot of code in my time, and I still get that will to strangle people who leave me with poorly written code. You should always assume that your code will be looked after by someone else.... and that that someone else can find out where you live... you've been warned

    QuantumPete
    And even if it's just you that will be maintaining it; unless you have an extremely good memory, you'll probabaly forget what the magic number meant a few weeks/months later.

  3. #18
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    No worries there. I only use magic numbers for temporary or debug code which I would delete in 10 minutes anyway.

  4. #19
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    And even if it's just you that will be maintaining it; unless you have an extremely good memory, you'll probably forget what the magic number meant a few weeks/months later.
    Actually, I've run into error 5 so much, I know what it means, even from month to month or year to year. Kind of like everyone knows what 0xC0000005 means.
    But that's besides the point, why would this happen? Does anyone know of any previous API calls that could do this?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  5. #20
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Code:
    C:\\Documents and Settings\\Yarin\\Desktop\\TESTFILE.txt");
    I would suggest that you check the security properties of the Documents and Settings folder on your Win2k machine to verify that you have the necessary permissions to modify (write to) TESTFILE.txt

  6. #21
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    Yes, full rights, all are set to allow.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  7. #22
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Both code paths have beeps. Are you sure you're hearing the one you think you're hearing?

  8. #23
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703
    Well, considering that you are invoking so many API calls (which can clear and set an error themselves) after CreateFile before calling GetLastError, the code you're getting may not relate to CreateFile at all...
    Code:
    #include <cmath>
    #include <complex>
    bool flip(bool value)
    {
           return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0)*(1 << (value + 2)))
        ).real() < 0;
    }

  9. #24
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    CreateFile() would set the last error to 0 (ERROR_SUCCESS) then.

  10. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    the docs say that some functions set ERROR_SUCCESS, and some don't. CreateFile doesn't say whether it does or doesn't, so it might not.

  11. #26
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    If the function succeeds with CREATE_ALWAYS or OPEN_ALWAYS and the file already existed, GetLastError() returns ERROR_ALREADY_EXISTS, though the function has succeeded. Otherwise, on success, it returns 0. On failure it always returns the error code.

  12. #27
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    ok, right you are, except if it's not a valid path.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. It works just fine but
    By jcmhex in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2005, 06:53 PM
  2. Fstream problem 2000 and xp
    By ~Kyo~ in forum C++ Programming
    Replies: 1
    Last Post: 12-06-2004, 09:05 PM
  3. Wont run in X, works fine in alt+F1 terminal
    By zmerlinz in forum Linux Programming
    Replies: 5
    Last Post: 04-28-2004, 11:58 AM
  4. My computer works just fine
    By Betazep in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 07-02-2002, 08:51 AM
  5. Replies: 6
    Last Post: 01-07-2002, 01:46 AM

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