I am trying to get volume serial number with winapi in c++
I have the following code:
DWORD VolumeSerialNumber=0;
GetVolumeInformation(L"c:\\", NULL, NULL, &VolumeSerialNumber, NULL, NULL, NULL, NULL);
it works fine and returns VolumeSerialNumber=571477456
but in cmd
, when i use dir
I get:
C:\Users\User>dir
Volume in drive C is Windows
Volume Serial Number is 2210-0DD0
how do i convert 571477456 to 2210-0DD0 ?
You just need to print the value in hex instead of decimal, using the %X
format specifier:
printf("VolumeSerialNumber: 0x%X\n", VolumeSerialNumber);
Which will output:
0x22100dd0
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));
Which will output:
Volume Serial Number is 2210-0DD0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With