From: George on
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
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
"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
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
Hi Victor,


How about using OpenFile() with OF_SHARE_EXCLUSIVE? If successful, I need to
close the file.


regards,
George
 |  Next  |  Last
Pages: 1 2 3
Prev: OLESTR
Next: partial specialization