One-day Windows API training (62) getdiskfreespaceex Function

Source: Internet
Author: User
Once a customer complained to me about the poor use of my software, causing them to lose a lot of data. Later, I carefully checked the log and analyzed the cause, which is actually very simple, that is, the disk space is not enough. I told the customer that their computer disk space was insufficient, which caused an error. However, the customer asked me why I didn't prompt that the disk space was insufficient. Yes. Why is there no insufficient disk space? To solve this problem, you need to use the getdiskfreespaceex function. The declaration of function direction is as follows: direction (_ in_opt lpcstr lpdirectoryname, _ out_opt pularge_integer outer, _ out_opt outer, _ out_opt pularge_integer outer); direction (_ in_opt lpdirectoryname, _ out_opt pularge_integer lpfreebytesavailabletocaller, _ out_opt Pu Large_integer lptotalnumberofbytes, _ out_opt pularge_integer bytes); # ifdef Unicode # define getdiskfreespaceex getdiskfreespaceexw # else # define getdiskfreespaceex limit # endif //! Unicode lpdirectoryname is the name of the drive. Lpfreebytesavailabletocaller is the disk space available to users. Lptotalnumberofbytes is the total disk space. Lptotalnumberoffreebytes is the free disk space. The preceding values are in bytes. Example of calling a function: #001 // obtain the remaining disk space. #002 // Cai junsheng 2007/11/01 QQ: 9073204 Shenzhen #003 void diskfree (void) #004 {# 005 // #006 ularge_integer nfreebytesavailable; #007 ularge_integer handle; #008 ularge_integer handle; #009 // #010 if (getdiskfreespaceex (_ T ("C:"), #011 & nfreebytesavailable, #012 & ntotalnumberofbytes, #013 & ntotalnumberoffreebytes )) #014 {#015 tchar chbuf [256]; #016 wsprintf (chbuf, _ T ("AV = % i64d, total = % i64d, free = % i64d/R/N "), #017 nfreebytesavailable, #018 ntotalnumberofbytes, #019 bytes); #020 outputdebugstring (chbuf); #021} #022}

 

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.