Re: Questions of CreateFile and WriteFile
From: Arnaud Debaene (adebaene_at_club-internet.fr)
Date: 02/13/05
- Next message: William DePalo [MVP VC++]: "Re: try and __try"
- Previous message: helmut zeisel: "Re: basic_ios::init: multiple call standard conform?"
- In reply to: ad: "Questions of CreateFile and WriteFile"
- Next in thread: Ken Hagan: "Re: Questions of CreateFile and WriteFile"
- Reply: Ken Hagan: "Re: Questions of CreateFile and WriteFile"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 13 Feb 2005 23:24:48 +0100
ad wrote:
> 1. CreateFile(fileName, FLAG,
> FILE_SHARE_WRITE|FILE_SHARE_READ,
> NULL,
> OPEN_EXISTING,
> NULL,
> NULL);
>
> To share the access to "fileName" among processes, does FLAG have to
> be set to "GENERIC_WRITE|GENERIC_READ"?
The second parameter ("FLAG" as you have called it) is the desired access
mode to the file(read, write, execute, etc...). It has nothing to do with
the saring mode of the file, except that you can't open a file in a given
mode (say, for writing), if another process has already opened the file with
a sharing mode that restrict this access to other processes (ie, it has
opened the file without FILE_SHARE_WRITE).
> To share the access to "fileName" among threads in a process, does
> FLAG have to be set to "GENERIC_WRITE|GENERIC_READ" too?
File sharing and protection is at process level : Threads of the same
process have complete access to one another resources.
> 2. WriteFile
>
> "The WriteFile function writes data to a file at the position
> specified by the file pointer. This function is designed for both
> synchronous and asynchronous operation."
>
> How to specify the position in a file for writing in Win32?
SetFilePointer(Ex) or SetEndOfFile.
> Can "WriteFile" to write data beyond END-OF-FILE? (For example, file
> size is 1K, but WriteFile from the position of 20K.)
No. But you can use SetEndOfFile to fill from 1K to 20K offset with
undefined data. If you need to create huge files which contains a lot of
"empty" spaces (logically, 0s), you may be intersted in sparse files : see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/sparse_files.asp
> MSDN says that "You cannot perform asynchronous write operations on
> ..., or disk files." Why can't write asynchronously in a disk file?
This is true only on Windows 95/98/Me, because those systems don't support
asynchronous file access!
Arnaud
MVP - VC
- Next message: William DePalo [MVP VC++]: "Re: try and __try"
- Previous message: helmut zeisel: "Re: basic_ios::init: multiple call standard conform?"
- In reply to: ad: "Questions of CreateFile and WriteFile"
- Next in thread: Ken Hagan: "Re: Questions of CreateFile and WriteFile"
- Reply: Ken Hagan: "Re: Questions of CreateFile and WriteFile"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|