- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I'm trying to use the Windows API function GetVolumeInformation located in kernel32 to read the Volume Serial Number for drive C:.
For my system it reports the Volume Serial Number = 4937288.
But this is not the correct Volume Serial Number (=72919446) - as given both by an equivalent program in VB6 and also the output from the DOS command VOL C:
My simple program is shown below (adapted from http://www.pgroup.com/userforum/viewtopic.php?p=4180&sid=6d107daf5726667006cde0266a6b2d3a).
Can anyone tell me what I'm doing wrong in Fortran?
Thanks, Leigh
! code adapted from http://www.pgroup.com/userforum/viewtopic.php?p=4180&sid=6d107daf5726667006cde0266a6b2d3a
program main
USE KERNEL32
Integer(BOOL) iret
Character*256 RootPathName
Character*256 VolumeNameBuffer
Integer(DWORD) VolumeNameSize
Integer(HANDLE) VolumeSerialNumber
Integer(HANDLE) MaximumComponentLength
Integer(HANDLE) FileSystemFlags
Character*256 FileSystemNameBuffer
Integer(DWORD) FileSystemNameSize
RootPathName = "c:"
VolumeNameSize = 256
FileSystemNameSize = 256
iret = GetVolumeInformation( &
TRIM(RootPathName), &
VolumeNameBuffer, &
VolumeNameSize, &
VolumeSerialNumber, &
MaximumComponentLength, &
FileSystemFlags, &
FileSystemNameBuffer, &
FileSystemNameSize)
print *,"File system name: ", FileSystemNameBuffer
print *,"Volume serial number: ", VolumeSerialNumber
end program main
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Integer(HANDLE) VolumeSerialNumber
Integer(HANDLE) MaximumComponentLength
Integer(HANDLE) FileSystemFlags
These variables are HANDLEs. Add LOC() when you call API.
[cpp]iret = GetVolumeInformation( & TRIM(RootPathName), & VolumeNameBuffer, & VolumeNameSize, & LOC(VolumeSerialNumber), & LOC(MaximumComponentLength), & LOC(FileSystemFlags), & FileSystemNameBuffer, & FileSystemNameSize) print '(a, Z16)',"Volume serial number: ", VolumeSerialNumber [/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
These variables are HANDLEs. Add LOC() when you call API.
[cpp]iret = GetVolumeInformation( &
TRIM(RootPathName), &
VolumeNameBuffer, &
VolumeNameSize, &
LOC(VolumeSerialNumber), &
LOC(MaximumComponentLength), &
LOC(FileSystemFlags), &
FileSystemNameBuffer, &
FileSystemNameSize)
print '(a, Z16)',"Volume serial number: ", VolumeSerialNumber
[/cpp]
Thanks, yamajun, for your help. Those changes fixed the problem.
Regards, Leigh

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page