check file opened or not?

This is a discussion on check file opened or not? within the Windows Programming forums, part of the Platform Specific Boards category; Originally Posted by Bubba I don't think using ifstream is the right approach. Windows would be the only one who ...

  1. #31
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bubba View Post
    I don't think using ifstream is the right approach. Windows would be the only one who could really tell you if the file was opened by a process. Just because a file is opened in one process does not mean that it is in exclusive mode. This is actually relying on a side effect of what Windows may do to get ifstream to report the information you want. In essence you are using ifstream to report something that it is not responsible for.
    I take it you mean that filebuf::sh_none is not guaranteed to open the file in "exclusive mode" - which is what is required for this to work.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #32
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Bubba,


    What is your proposed solution if you do not propose to use ifstream below?

    Quote Originally Posted by Bubba View Post
    I don't think using ifstream is the right approach. Windows would be the only one who could really tell you if the file was opened by a process. Just because a file is opened in one process does not mean that it is in exclusive mode. This is actually relying on a side effect of what Windows may do to get ifstream to report the information you want. In essence you are using ifstream to report something that it is not responsible for.

    Hi Mats,


    Quote Originally Posted by matsp View Post
    I take it you mean that filebuf::sh_none is not guaranteed to open the file in "exclusive mode" - which is what is required for this to work.

    --
    Mats
    I think it is guaranteed. Here is what MSDN said,

    http://msdn2.microsoft.com/en-us/lib...33(VS.60).aspx

    --------------------
    filebuf::sh_none Exclusive mode — no sharing.
    --------------------

    Any comments?


    regards,
    George

Page 3 of 3 FirstFirst 123
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. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Function is called and I am trying to open a file
    By tommy69 in forum C Programming
    Replies: 88
    Last Post: 05-06-2004, 08:33 AM

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