home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4581 < prev    next >
Encoding:
Internet Message Format  |  1993-01-04  |  1.8 KB

  1. Path: sparky!uunet!cs.utexas.edu!uwm.edu!ogicse!news.u.washington.edu!sumax.seattleu.edu!sumax.seattleu.edu!not-for-mail
  2. From: kburrows@sumax.seattleu.edu (Kevin Burrows)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: avoiding sharing violations
  5. Message-ID: <1iaeobINN6h4@sumax.seattleu.edu>
  6. Date: 4 Jan 93 06:46:35 GMT
  7. Article-I.D.: sumax.1iaeobINN6h4
  8. References: <1i9ctpINNbba@life.ai.mit.edu>
  9. Organization: Seattle University
  10. Lines: 37
  11. NNTP-Posting-Host: sumax.seattleu.edu
  12.  
  13.  
  14. >So my question is, how can I determnine whether some other application has a
  15. >particular file open so I don't try to open it and get slapped across the
  16. >wrist?  What combination of flags in OpenFile gives me some code that
  17. >tells me the file is in use (or hangs me up until it it not), WITHOUT
  18. >giving me these unpleasant `sharing violations'?
  19.  
  20. I encountered problems with Openfile that may be similar to yours.
  21. In my case I have multiple computers on a network simultaneously accessing 
  22. a single file. To create the file I used a call similar to the following:
  23.  
  24.    hFile = OpenFile( szFileName, OFile, 
  25.                      OF_CREATE | OF_READWRITE | OF_SHARE_DENY_NONE );
  26.  
  27. However, when a second application attempted to open the file access was
  28. denied!  The call used by the second application was the following:
  29.  
  30.    hFile = OpenFile( szFileName, OFile, 
  31.                      OF_READWRITE | OF_SHARE_DENY_NONE );
  32.  
  33. I was able to resolve this problem by first creating the file, closing
  34. it, then reopening it:
  35.  
  36.    hFile = OpenFile( szFileName, OFile, OF_CREATE );
  37.    if ( hFile != -1 )
  38.       {
  39.       _lclose( hFile );
  40.       hFile = OpenFile( szFileName, OFile, 
  41.                         OF_READWRITE | OF_SHARE_DENY_NONE );
  42.       }
  43.  
  44. With this code I enabled simultaneous access to the file by multiple 
  45. applications.
  46.  
  47. Hope this helps. Good luck.
  48.  
  49. Kevin
  50.