Archive: Vol name -- getting a string from a Kernel call


Vol name -- getting a string from a Kernel call
Hello,

I'm trying to retrieve the volume name (the disk label) for a removable disk. But I only see an empty string.

Thank you for your help,

Larry the newbie
ps. I indeed read the manual, system call docs, & Dll example. Unfortunately to no avail.


; Based on http://nsis.sourceforge.net/Get_Disk..._Serial_Number
; first and only parameter - Drive to check. Returns the Disk label (Volume Name)
; Remember to free the memory by calling System::Free <var>
Function GetDiskVolumeName
Pop $1 ; get parameter

System::Alloc 1024 ; Allocate string body
Pop $0 ; Get the allocated string's address

MessageBox MB_OK "Looking for drive $1 label"

!define GetVolumeInformation "Kernel32::GetVolumeInformation(t,*t,i,*i,*i,*i,t,i) i"
System::Call '${GetVolumeInformation}("$1",.r0,1024,,,,,)'

MessageBox MB_OK "$1 Label: $0"
; Push result
Push $0

FunctionEnd ; GetDiskVolumeName

Pass 1024 for the last parameter as well.

The second parameter is also a string pointer, not a pointer to a string pointer. It should be of type `t` and not `*t`.


Success! Thank you very much. Here is the complete corrected code:


; Based on http://nsis.sourceforge.net/Get_Disk..._Serial_Number
; First and only parameter - Drive to check.
; Eg "C:\" -- NOT "C" or anything else
; Returns the Disk label (Volume Name)
; Remember to free the memory by calling System::Free <var>

Function GetDiskVolumeName
Pop $1 ; get parameter

System::Alloc 1024 ; Allocate string body
Pop $0 ; Get the allocated string's address

!define GetVolumeInformation "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i"
System::Call '${GetVolumeInformation}("$1",.r0,1024,,,,,1024)' ;

Push $0 ; Push result
FunctionEnd ; GetDiskVolumeName