如何从Inno Setup中的GetVolumeInformation获取卷名?

时间:2018-05-16 12:15:46

标签: winapi installer inno-setup pascalscript

我尝试从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类型。

1 个答案:

答案 0 :(得分:1)

withColumn("newcolumnname", ....

(代码适用于Unicode version of Inno Setup)。