Hi there:
Is there any APIs to detect the files are being operating by some API ,
such as WriteFile?

Re: File IO related issue by David

David
Sat Jul 21 13:04:27 CDT 2007

> Is there any APIs to detect the files are being operating by some API ,
>such as WriteFile?

What are you trying to achieve (over and above what you've mentioned)?

Dave

Re: File IO related issue by hangaround

hangaround
Sat Jul 21 22:00:01 CDT 2007



"David Lowndes" wrote:

> > Is there any APIs to detect the files are being operating by some API ,
> >such as WriteFile?
>
> What are you trying to achieve (over and above what you've mentioned)?
>
> Dave
>

for example, when I Open a file (using CreateFile or other APIs), I could
know the file is being write(using WriteFile) by other thread.

Re: File IO related issue by Igor

Igor
Sat Jul 21 22:24:33 CDT 2007

"hangaround" <hangaround@discussions.microsoft.com> wrote in message
news:90AF9B3F-D792-41F5-A92D-1E8335532953@microsoft.com
> for example, when I Open a file (using CreateFile or other APIs), I
> could know the file is being write(using WriteFile) by other thread.

Don't pass FILE_SHARE_WRITE flag in dwShareMode parameter. Then
CreateFile will fail if the file is already opened for writing.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: File IO related issue by hangaround

hangaround
Sat Jul 21 23:32:02 CDT 2007



"Igor Tandetnik" wrote:

> "hangaround" <hangaround@discussions.microsoft.com> wrote in message
> news:90AF9B3F-D792-41F5-A92D-1E8335532953@microsoft.com
> > for example, when I Open a file (using CreateFile or other APIs), I
> > could know the file is being write(using WriteFile) by other thread.
>
> Don't pass FILE_SHARE_WRITE flag in dwShareMode parameter. Then
> CreateFile will fail if the file is already opened for writing.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>

If I use CloseHandle to the file , which is using by WriteFile by other
thread, then what will happen?

Re: File IO related issue by Carl

Carl
Sun Jul 22 00:49:01 CDT 2007

hangaround wrote:
>
> If I use CloseHandle to the file , which is using by WriteFile by
> other thread, then what will happen?

Haven't you read the replies to the thread on this very question that you
started on July 17th?

For well-defined behavior, don't do this. Whatever happens is "luck".

-cd



Re: File IO related issue by hangaround

hangaround
Sun Jul 22 00:56:00 CDT 2007



"Carl Daniel [VC++ MVP]" wrote:

> hangaround wrote:
> >
> > If I use CloseHandle to the file , which is using by WriteFile by
> > other thread, then what will happen?
>
> Haven't you read the replies to the thread on this very question that you
> started on July 17th?
>
> For well-defined behavior, don't do this. Whatever happens is "luck".
>
> -cd
>
>
>

OK, I get you, thanks a lot.