I try to get the volume name in Inno Setup from Windows API. The serial number is returned correctly but the volume name is empty. I used the code of 'kobik' in this thread:
How can I use GetVolumeInformation
in Inno Setup?
This is my function in Inno Setup:
function FindVolumeName(const Drive: string): string;
var
FileSystemFlags: DWORD;
VolumeSerialNumber: DWORD;
MaximumComponentLength: DWORD;
ErrorCode: integer;
VolumeLabel: PChar;
begin
Result := '';
{ Note on passing PChars using RemObjects Pascal Script: }
{ '' pass a nil PChar }
{ #0 pass an empty PChar }
if (GetVolumeInformation(pchar(drive), volumeLabel, MAX_LENGTH, VolumeSerialNumber, MaximumComponentLength, FileSystemFlags, '', 0)) then
begin
Result := WordToHex(HiWord(VolumeSerialNumber)) + '-' + WordToHex(LoWord(VolumeSerialNumber));
end
else
begin
errorCode:= GetLastError();
MsgBox (SysErrorMessage (errorCode), mbError, MB_OK);
end;
MsgBox('VolumeLabel: ' +volumeLabel, mbInformation, MB_OK);
end;
I'm not sure how to use the PChar
type.