• Advertisement
Sign in to follow this  

CreateFile and locking files

This topic is 3983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use CreateFile (Win32 fuction) to open a file and cause it to be locked from writing by other processes but have them still be able to open and read it. It works fine in XP, but in 98 nothing seems to be able to read or write to it. Just wondering if its something to do with the Win98 operating system. This is the code I'm using to open the file:
file = CreateFile("test.txt", 
                  GENERIC_WRITE,          // open for reading
                  FILE_SHARE_READ,       // share for reading
		  NULL,                  // default security
		  OPEN_EXISTING,         // existing file only
		  FILE_ATTRIBUTE_NORMAL, // normal file
		  NULL);   

Share this post


Link to post
Share on other sites
Advertisement
In your call example you mixed the two

GENERIC_WRITE, // open for reading <- nope, open for writing
FILE_SHARE_READ, // share for reading

Share this post


Link to post
Share on other sites
I had it as GENERIC_READ before but I was doing something that made it not work and changed it to _WRITE and forgot to put it back.

With fopen() I'm fairly sure you could open a file in write mode and still be able to have other processes open the same file for reading/writting. I was wondering if there was something funny going on with CreateFile() that I didn't know about or couldn't find on MSDN.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement