Windows API one-day training (53) createfile Function

Source: Internet
Author: User

It is a very important function to save useful data in the demand of software. For example, the daily stock market data needs to be saved to generate a K-line chart. For example, the log of the game client needs to be saved so that the client can send the log back when an error occurs to analyze the cause of the error. For example, when a bank makes a daily transaction, it also needs to save all transaction data to a file for backup for settlement. In the field of data collection, more data needs to be stored. For example, reading video and voice data from DV generates 12 GB of giant files. For example, when you read a DVD, the size of a virtual optical drive is also 9 GB. Therefore, creating a file is a very common function, which must be mastered and used very much. Of course, this createfile function not only creates files, but also supports functions such as serial port, parallel port, network, and USB device.


The createfile function declaration is as follows:

Winbaseapi
_ Out
Handle
Winapi
Createfilea (
_ In lpcstr lpfilename,
_ In DWORD dwdesiredaccess,
_ In DWORD dw1_mode,
_ In_opt lpsecurity_attributes lpsecurityattributes,
_ In DWORD dwcreationdisposition,
_ In DWORD dwflagsandattributes,
_ In_opt handle htemplatefile
);
Winbaseapi
_ Out
Handle
Winapi
Createfilew (
_ In lpcwstr lpfilename,
_ In DWORD dwdesiredaccess,
_ In DWORD dw1_mode,
_ In_opt lpsecurity_attributes lpsecurityattributes,
_ In DWORD dwcreationdisposition,
_ In DWORD dwflagsandattributes,
_ In_opt handle htemplatefile
);
# Ifdef Unicode
# Define createfile createfilew
# Else
# Define createfile createfilea
# Endif //! Unicode
Lpfilename is the name of a file or device.
Dwdesiredaccess is an access attribute.
Dww.mode is a shared attribute.
Lpsecurityattributes is a security attribute.
Dwcreationdisposition is the creation attribute.
Dwflagsandattributes is a file identifier and attribute.
Htemplatefile is a file template.

An example of calling a function is as follows:
#001 // create a file.
#002 // Cai junsheng 2007/10/18 QQ: 9073204 Shenzhen
#003 void createfiledemo (void)
#004 {
#005 //
#006 handle hfile =: createfile (_ T ("createfiledemo.txt"), // name of the file to be created.
#007 generic_write, // write the file.
#008 0, // do not share read/write.
#009 null, // default security attribute.
#010 create_always, // create a file if the file exists.
#011 file_attribute_normal, // common file.
#012 null); // The template file is empty.
#013
#014 if (hfile = invalid_handle_value)
#015 {
#016 //
#017 outputdebugstring (_ T ("createfile fail! \ R \ n "));
#018}
#019}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/10/18/1831801.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.