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)

相关推荐
你是人间五月天9 小时前
sentinel实现控制台与nacos数据双向绑定
windows·sentinel
UnnamedOrange9 小时前
ROS2 配置 linter 的代码格式化工具为 clang-format
c++·cmake
Dobby_059 小时前
【面试题】C++系列(一)
c++·面经
一拳一个呆瓜9 小时前
【MFC】对话框节点属性:Language(语言)
c++·mfc
点云侠11 小时前
解决Visual Studio 2022编译工程速度慢的问题
开发语言·c++·ide·算法·计算机视觉·visual studio
小猫挖掘机(绝版)12 小时前
通过tailscale实现一台电脑上vscode通过ssh连接另一台电脑上的VMware Linux 虚拟机
linux·windows·vscode·ubuntu·ssh
ajassi200012 小时前
开源 C++ QT Widget 开发(十三)IPC通讯--本地套接字 (Local Socket)
linux·c++·qt·开源
Q741_14712 小时前
C++ 前缀和 高频笔试考点 实用技巧 牛客 DP34 [模板] 前缀和 题解 每日一题
开发语言·c++·算法·前缀和·牛客网
YaoYuan932312 小时前
C++ 容器——unordered_xxx
c++
凤年徐13 小时前
C++类和对象(上):从设计图到摩天大楼的构建艺术
c语言·开发语言·c++·类和对象