Prog crashes upon read of system file

This is a discussion on Prog crashes upon read of system file within the C++ Programming forums, part of the General Programming Boards category; When my program reads index.dat of the internet cache it crashes, but it reads a copy of the file just ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question Prog crashes upon read of system file

    When my program reads index.dat of the internet cache it crashes, but it reads a copy of the file just fine. How come simple apps like notepad can read it but my prog can't?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Why would your program crash? Are you being an idiot and not checking if the file actually opened before you try to mess with it?

    Those "simple apps" are opening the file in a shared mode I believe, unlike what you're probably doing.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Why would your program crash? Are you being an idiot and not checking if the file actually opened before you try to mess with it?
    You where right & wrong, I was checking, but the wrong way. After running through my code again, I changed if(!hFile) to if(hFile==INVALID_HANDLE_VALUE).
    Those "simple apps" are opening the file in a shared mode I believe, unlike what you're probably doing.
    What is shared mode? ...why are 'simple apps' in quotes?
    EDIT: Nevermind, I got it.
    EDIT: Nope, opening the file in shared mode doesn't work either, what's wrong here??
    Last edited by Queatrix; 07-23-2007 at 08:21 PM.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Is GetLastError() applicable in this case? If so, what is it returning?

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Yep, I was afraid of that, it's a sharing violation (32)... but still, how can other apps do it?

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Ah ha.
    Thanks for the help, but I got it. This guy had the same problem, and got it fixed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM

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