GetVolumeInformation函数使用记录

函数原型

BOOL GetVolumeInformationA(

in, optional\] LPCSTR lpRootPathName, \[out, optional\] LPSTR lpVolumeNameBuffer, \[in\] DWORD nVolumeNameSize, \[out, optional\] LPDWORD lpVolumeSerialNumber, \[out, optional\] LPDWORD lpMaximumComponentLength, \[out, optional\] LPDWORD lpFileSystemFlags, \[out, optional\] LPSTR lpFileSystemNameBuffer, \[in\] DWORD nFileSystemNameSize ); ### 在windows中有两种 普通:GetVolumeInformationA 宽字符版:GetVolumeInformationW 这里我以**普通**GetVolumeInformationA为例; ## **先看官方文档解释** 官方文档:[GetVolumeInformationA 函数 (fileapi.h) - Win32 apps \| Microsoft Learn](https://learn.microsoft.com/zh-cn/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa "GetVolumeInformationA 函数 (fileapi.h) - Win32 apps | Microsoft Learn") ![](https://i-blog.csdnimg.cn/direct/0b408b7fe6044d849895d6cf2fbda47e.png) 文档不短,其大概意思就是根据传入的盘符路径,获取盘符的各种信息; 接下来就是测试这个函数的功能; 直接上代码: 环境:vsstudio2019 ```cpp #include #include int main() { char volumeName[MAX_PATH]; char fileSystemName[MAX_PATH]; DWORD serialNumber; DWORD maxComponentLength; DWORD fileSystemFlags; // 获取F盘的信息(注意:其中的F填你自己要查询的盘符) if (!GetVolumeInformationA("F:\\", volumeName, MAX_PATH, &serialNumber, &maxComponentLength, &fileSystemFlags, fileSystemName, MAX_PATH)) { printf("获取F盘信息失败,错误码:%d\n", GetLastError()); return 1; } // 输出F盘的相关信息 printf("盘符F的卷标名称:%s\n", volumeName); printf("盘符F的序列号:%lu\n", serialNumber); printf("盘符F的文件系统名称:%s\n", fileSystemName); printf("盘符F的最大组件长度:%lu\n", maxComponentLength); printf("盘符F的文件系统标志:%lu\n", fileSystemFlags); return 0; } ``` 输出如下: ![](https://i-blog.csdnimg.cn/direct/8d7d987f0c544b599e98f0b1dce591df.png)

相关推荐
lingran__1 天前
速通ACM省铜第三天 赋源码(Double Perspective和Trip Shopping和Hamiiid, Haaamid... Hamid?)
c++·算法
凤城老人1 天前
C++使用拉玛努金公式计算π的值
开发语言·c++·算法
YaoYuan93231 天前
C++ 类型推导(第一部分)
c++
夜猫逐梦1 天前
【VC】 error MSB8041: 此项目需要 MFC 库
c++·mfc
人工干智能1 天前
科普:在Windows个人电脑上使用Docker的极简指南
windows·docker·容器
姓刘的哦1 天前
Qt中的QWebEngineView
数据库·c++·qt
C_player_0011 天前
——贪心算法——
c++·算法·贪心算法
SundayBear1 天前
QT零基础入门教程
c++·qt
kyle~1 天前
排序---插入排序(Insertion Sort)
c语言·数据结构·c++·算法·排序算法
奔跑吧邓邓子1 天前
【C++实战⑦】C++函数实战:从基础到项目应用
c++·实战·函数