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

文档不短,其大概意思就是根据传入的盘符路径,获取盘符的各种信息;

接下来就是测试这个函数的功能;

直接上代码:

环境:vsstudio2019

cpp 复制代码
#include <windows.h>
#include <stdio.h>

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;
}

输出如下:

相关推荐
凡人叶枫7 小时前
Effective C++ 条款30:透彻了解 inlining 的里里外外
linux·开发语言·c++·嵌入式开发·effective c++
noipp7 小时前
推荐题目:洛谷 P10907 [蓝桥杯 2024 国 B] 蚂蚁开会
c语言·c++·算法·编程·洛谷
学逆向的8 小时前
C++纯虚函数
开发语言·c++·网络安全
caimouse8 小时前
Reactos 第 8 章 结构化异常处理 — 8.2 系统空间的结构化异常处理
windows
caimouse8 小时前
Reactos 第 7 章 视窗报文 — 7.3 Win32k 的用户空间回调机制
windows
caimouse8 小时前
Reactos 第 9 章 设备驱动 — 9.5 一组PnP设备驱动模块的实例
网络·windows
神成19 小时前
vmware 上 win7 系统按照 vmware tool
windows
凡人叶枫9 小时前
Effective C++ 条款22:将成员变量声明为 private
linux·开发语言·c++
虾壳云官方9 小时前
OpenClaw 2.7.9 Windows 一键部署教程:零基础也能搭建 AI 自动化助手
运维·人工智能·windows·自动化·openclaw·openclaw一键部署
坚果派·白晓明10 小时前
【鸿蒙PC】SDL3 移植:AtomCode Skills 4 步速通多媒体库适配
c++·华为·ai编程·harmonyos·atomcode·c/c++三方库