I think my post was something like:
hehe yes
https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getvolumeinformationa
says we need MAX_PATH + 1 which is 260+1
but as we’re covering Unicode in the same function then we need to allocate the space and set things to *2 so 522
We don’t need to worry about longer filenames that are possible in windows 10 and later because the API we’re calling isn’t in the list of calls shown on the page you linked.
So this should be good:
[code]Function GetVolumeName(extends f As FolderItem) As String
#If TargetWin32
Soft Declare Function GetVolumeInformationA Lib “Kernel32” ( root As CString, _
volName As Ptr, volNameSize As Integer, ByRef volSer As Integer, ByRef _
maxCompLength As Integer, ByRef sysFlags As Integer, sysName As Ptr, _
sysNameSize As Integer ) As Boolean
Soft Declare Function GetVolumeInformationW Lib “Kernel32” ( root As WString, _
volName As Ptr, volNameSize As Integer, ByRef volSer As Integer, ByRef _
maxCompLength As Integer, ByRef sysFlags As Integer, sysName As Ptr, _
sysNameSize As Integer ) As Boolean
Dim volName As New MemoryBlock( 522 )
Dim sysName As New MemoryBlock( 522 )
Dim volSerial, maxCompLength, sysFlags As Integer
If System.IsFunctionAvailable( “GetVolumeInformationW”, “Kernel32” ) Then
Call GetVolumeInformationW( Left( f.NativePath, 3 ), volName, 261 , volSerial, maxCompLength, _
sysFlags, sysName, 261 )
Return volName.WString( 0 )
Else
Call GetVolumeInformationA( Left( f.NativePath, 3 ), volName, 261 , volSerial, maxCompLength, _
sysFlags, sysName, 261 )
Return volName.CString( 0 )
End If
#EndIf
End Function[/code]