我尝试从Windows API获取Inno Setup中的卷名。序列号正确返回,但卷名为空。我在这个帖子中使用了'kobik'的代码:
How can I use GetVolumeInformation
in Inno Setup?
这是我在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;
我不确定如何使用PChar
类型。