Silverfrost Forums

Welcome to our forums

WinAPI-Call fails under Windows 10

8 Apr 2021 3:48 #27452

The following codes uses a WinAPI-Call to GetVolumeInformationA to read out the volume serial number that the operating system assigns when a hard disk is formatted, like the command VOL. It runs as awaited unter Windows 7 but fails now under Windows 10, where it worked some months ago. However I am not certain wether it is a windows issue. I would be grateful if somebody could test it.

PROGRAM SerialNumber
USE mswin, ONLY : GetVolumeInformation
USE ISO_FORTRAN_ENV, ONLY : COMPILER_VERSION
IMPLICIT NONE
INTEGER(KIND=4) :: VolumeSerialNumber, MaxCompLength, FileSystemFlags, FileSystemNameSize, VolumeNameSize
CHARACTER(LEN=256) :: VolumeName, FileSystemName, PathName='C:'
LOGICAL(KIND=3) :: Res
Res=GetVolumeInformation(PathName, VolumeName, VolumeNameSize, VolumeSerialNumber, & 
    & MaxCompLength, FileSystemFlags, FileSystemName, FileSystemNameSize)
WRITE(*,'(1X,L1)') Res
WRITE(*,'(1X,A,Z8)') 'Volume Serial Number is ', VolumeSerialNumber
WRITE(*,*) 'Volumename is ', TRIM(VolumeName)
WRITE(*,*) 'Filesystem is ', TRIM(FileSystemName)
WRITE(*,*) 'Compiler is ', COMPILER_VERSION()
END PROGRAM SerialNumber

Output under Windows 7

T Volume Serial Number is 2A7F77E6 Volumename is Filesystem is NTFS Compiler is FTN95 v8.71

Output under Windows 10

F Volume Serial Number is 0 Volumename is Filesystem is 5%jöAd< Compiler is FTN95 v8.71

12 Apr 2021 11:31 #27497

After further investigation, the code runs normally under Windows 10 when setting SET __COMPAT_LAYER=WIN7RTM before calling the executable from the console.

When starting the executable from Plato, the same can be achieved by setting the Windows compatibilty mode of Plato.exe to 'Windows 7'

On some Windows 10 machines, it might be necessary to use INTEGER (KIND=3) to retrieve the correct volume serial number.

All operating systems used are 64 bit. Methink it is possibly a FTN95 issue.

15 Apr 2021 6:23 #27531

I have made a note to look into this.

15 Apr 2021 12:55 #27536

Two of the arguments need to be input values...

PROGRAM SerialNumber
STDCALL GETVOLUMEINFORMATION'GetVolumeInformationA'(STRING,STRING,VAL,REF,REF,REF,STRING,VAL):LOGICAL*4
INTEGER(KIND=3) :: VolumeSerialNumber, MaxCompLength, FileSystemFlags
CHARACTER(LEN=256) :: VolumeName, FileSystemName, PathName='C:'
INTEGER(KIND=3),PARAMETER::VolumeNameSize=256,FileSystemNameSize=256
CHARACTER(LEN=*),PARAMETER::fmt='(1X,A,Z8)'
LOGICAL(KIND=3) :: Res
Res=GetVolumeInformation(PathName, VolumeName, VolumeNameSize, VolumeSerialNumber, &
    & MaxCompLength, FileSystemFlags, FileSystemName, FileSystemNameSize)
WRITE(*,'(1X,L1)') Res
WRITE(*,fmt) 'Volume Serial Number is ', VolumeSerialNumber
WRITE(*,*) 'Volumename is ',             TRIM(VolumeName)
WRITE(*,*) 'Filesystem is ',             TRIM(FileSystemName)
WRITE(*,fmt) 'VolumeSerialNumber is ',   VolumeSerialNumber
WRITE(*,*) 'MaxCompLength is  ',         MaxCompLength
WRITE(*,fmt) 'FileSystemFlags is ',      FileSystemFlags
END PROGRAM SerialNumber
15 Apr 2021 2:06 #27542

Paul

Thanks a lot for your help. The pseudo-workaround I had found let me forget checking the basics. Sorry for this.

Please login to reply.