如何获得卷序列号 [英] how to get volume serial number

查看:562
本文介绍了如何获得卷序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得卷序列号在C ++ WINAPI

I am trying to get volume serial number with winapi in c++

我有以下的code:

DWORD VolumeSerialNumber=0; 
GetVolumeInformation(L"c:\\", NULL, NULL, &VolumeSerialNumber, NULL, NULL, NULL, NULL);

它工作正常,并返回 VolumeSerialNumber = 571477456
但在 CMD ,当我使用 DIR 我得到:

C:\Users\User>dir
 Volume in drive C is Windows
 Volume Serial Number is 2210-0DD0

如何转换为571477456 2210-0DD0?

how do i convert 571477456 to 2210-0DD0 ?

推荐答案

您只需要打印十六进制而不是十进制值,使用%X 格式说明:

You just need to print the value in hex instead of decimal, using the %X format specifier:

printf("VolumeSerialNumber: 0x%X\n", VolumeSerialNumber);

将输出:

0x22100dd0


如果您的真正的要求完全相同的输出,可以分开 DWORD 到它的下限和上限使用 LOWORD HIWORD 宏:


If you really require the exact same output, you can separate the DWORD into its lower and upper WORDS using the LOWORD and HIWORD macros:

printf("Volume Serial Number is %04X-%04X\n",
    HIWORD(VolumeSerialNumber),
    LOWORD(VolumeSerialNumber));

将输出:

Volume Serial Number is 2210-0DD0

这篇关于如何获得卷序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆