|
Prev: OLESTR
Next: partial specialization
From: George on 2 Apr 2008 09:57 Hello everyone, On Windows platform, which API could be used to check whether a file is opened (either by other thread or process or even the same thread) or not? C++ is fine. thanks in advance, George
From: Victor Bazarov on 2 Apr 2008 09:59 George wrote: > On Windows platform, which API could be used to check whether a file > is opened (either by other thread or process or even the same thread) > or not? Why bother? I believe you just try opening it and if it fails with the sharing violation, it's already open exclusively to somebody. If it doesn't fail, you do you job and close it and move on... V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
From: Alex Blekhman on 2 Apr 2008 10:01 "George" wrote: > On Windows platform, which API could be used to check whether a > file is > opened (either by other thread or process or even the same > thread) or not? Try to openthe file with exclusive access. If the call succeeds, thne nobody else is using the file. See `CreateFile' function in MSDN (pay attention to `dwShareMode' parameter). HTH Alex
From: George on 3 Apr 2008 02:49 Thanks Alex, How about using OpenFile() with OF_SHARE_EXCLUSIVE? I think it is better since using CreateFile, if successful, I have to delete the file, and my purpose is only to check whether some file is opened (used) or not. regards, George
From: George on 3 Apr 2008 02:50
Hi Victor, How about using OpenFile() with OF_SHARE_EXCLUSIVE? If successful, I need to close the file. regards, George |