Function prototype:
Handle createfile (
Lptstr lpfilename, // pointer to the file name
DWORD dwdesiredaccess, // write/read mode)
DWORD dw1_mode, // share mode
Lpsecurity_attributes lpsecurityattributes, // pointer to the Security Attribute
DWORD dwcreationdisposition, // how to create
DWORD dwflagsandattributes, // file attributes
Handle htemplatefile // used to copy the file handle
);
Quota List
Lpfilename string name of the file to be opened
Dwdesiredaccess long is assumed to be generic_read, indicating that the device is allowed to read; if it is generic_write, it indicates that the device is allowed to write a reply question (which can be used in combination); if it is zero, indicates that you only agree to obtain information related to a device.
Dw1_mode long, zero indicates that the file is not shared; file_1__read and/or file_1__write indicates that the file is shared.
Lpsecurityattributes security_attributes, pointing to a security_attributes structure pointer, defines the file security features (assuming the operating system supports)
Dwcreationdisposition long, one of the following constants:
Create_new: Creates a file. If the file exists, an error occurs.
Create_always: Creates a file and changes the previous file.
The open_existing file must already exist. Requirements from devices
Open_always: Create an open_always file if it does not exist.
Truncate_existing indicates that the existing file is shortened to zero length.
Dwflagsandattributes long, one or more of the following Constants
File_attribute_archive mark archive attributes
File_attribute_compressed: Mark the file as compressed, or mark it as the default compression mode of the file in the folder.
File_attribute_normal default attribute
File_attribute_hidden: hide a file or folder
The file_attribute_readonly file is read-only.
The file_attribute_system file is a system file.
The file_flag_write_through operating system must not postpone file write operations.
File_flag_overlapped agrees to overlap files
File_flag_no_buffering prohibits file caching. The file can only be written into the sector block of the disk volume.
File_flag_random_access optimizes the File Buffer for random seek questions
File_flag_sequential_scan optimizes the File Buffer for consecutive seek questions
File_flag_delete_on_close closes the last opened handle and deletes the file. Special for temporary files
You can also combine the following constant tags in Windows NT:
Security_anonymous, security_identification, security_impersonation, security_delegation, security_context_tracking, security_inclutive_only
Htemplatefile long. If it is not zero, a file handle is specified. The new file copies the extended attribute returned values from this file. If the operation is successful, the file handle is returned.
Invalid_handle_value indicates an error and getlasterror is set. Even if the function succeeds, if the file exists and create_always or open_always are specified, getlasterror is set to error_already_exists.
(From Baidu encyclopedia)
Instance:
1. Specify the file address directly in the function:
- VoidPlaycewav ()
- {
- Char* Pbuffer;
- DWORDRsize;
- IntFilesize = 0;
- IntI;
- HandleHopenfile = (Handle) Createfile (L"E: // A. Text", Generic_read, file_1__read, null, open_existing, null, null );
- If(Hopenfile = invalid_handle_value)
- {
- Hopenfile = NULL;
- Messageboxa (null,"Can not open the file","Playwav", Mb_ OK );
- }
- Filesize = getfilesize (hopenfile, null );
- Pbuffer = (Char*) Malloc (filesize );
- Readfile (hopenfile, pbuffer, filesize, & rsize, null );
- // You can display pbuffer in a certain area or write a file to check whether the file is read correctly.
- Free (pbuffer );
- }
2. Data Transmission of the file address through hosts:
- VoidPlaywav (Tchar* Path)
- {
- Char* Pbuffer;
- DWORDRsize;
- IntFilesize = 0;
- IntI;
- TcharSzpath [100];
- Memset (szpath, 0,Sizeof(Szpath ));
- _ Tcscpy (szpath, PATH );
- HandleHopenfile = (Handle) Createfile (szpath, generic_read, file_cmd_read, null, open_existing, null, null );
- If(Hopenfile = invalid_handle_value)
- {
- Hopenfile = NULL;
- Messageboxa (null,"Can not open the file","Playwav", Mb_ OK );
- }
- Filesize = getfilesize (hopenfile, null );
- Pbuffer = (Char*) Malloc (filesize );
- Readfile (hopenfile, pbuffer, filesize, & rsize, null );
- Free (pbuffer );
- }