Article View: comp.os.ms-windows.programmer.misc
Article #2463Re: avoiding sharing violations
From: Kevin Burrows
Date: Mon, 04 Jan 1993 06:46
Date: Mon, 04 Jan 1993 06:46
37 lines
1895 bytes
1895 bytes
>So my question is, how can I determnine whether some other application has a
>particular file open so I don't try to open it and get slapped across the
>wrist? What combination of flags in OpenFile gives me some code that
>tells me the file is in use (or hangs me up until it it not), WITHOUT
>giving me these unpleasant `sharing violations'?
I encountered problems with Openfile that may be similar to yours.
In my case I have multiple computers on a network simultaneously accessing
a single file. To create the file I used a call similar to the following:
hFile = OpenFile( szFileName, OFile,
OF_CREATE | OF_READWRITE | OF_SHARE_DENY_NONE );
However, when a second application attempted to open the file access was
denied! The call used by the second application was the following:
hFile = OpenFile( szFileName, OFile,
OF_READWRITE | OF_SHARE_DENY_NONE );
I was able to resolve this problem by first creating the file, closing
it, then reopening it:
hFile = OpenFile( szFileName, OFile, OF_CREATE );
if ( hFile != -1 )
{
_lclose( hFile );
hFile = OpenFile( szFileName, OFile,
OF_READWRITE | OF_SHARE_DENY_NONE );
}
With this code I enabled simultaneous access to the file by multiple
applications.
Hope this helps. Good luck.
Kevin
Technical Details
Message-ID:
<1iaeobINN6h4@sumax.seattleu.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!uwm.edu!ogicse!news.u.washington.edu!sumax.seattleu.edu!sumax.seattleu.edu!not-for-mailReferences:
<1i9ctpINNbba@life.ai.mit.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!uwm.edu!ogicse!news.u.washington.edu!sumax.seattleu.edu!sumax.seattleu.edu!not-for-mail From: kburrows@sumax.seattleu.edu (Kevin Burrows) Newsgroups: comp.os.ms-windows.programmer.misc Subject: Re: avoiding sharing violations Message-ID: <1iaeobINN6h4@sumax.seattleu.edu> Date: 4 Jan 93 06:46:35 GMT Article-I.D.: sumax.1iaeobINN6h4 References: <1i9ctpINNbba@life.ai.mit.edu> Organization: Seattle University Lines: 37 NNTP-Posting-Host: sumax.seattleu.edu