[英]How to get volume name from GetVolumeInformation in Inno Setup?
I try to get the volume name in Inno Setup from Windows API.我尝试从 Windows API 获取 Inno Setup 中的卷名。 The serial number is returned correctly but the volume name is empty.
序列号返回正确,但卷名为空。 I used the code of 'kobik' in this thread:
我在这个线程中使用了“kobik”的代码:
How can I use GetVolumeInformation
in Inno Setup?如何在 Inno Setup 中使用
GetVolumeInformation
?
This is my function 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;
I'm not sure how to use the PChar
type.我不确定如何使用
PChar
类型。
function GetVolumeInformation(
lpRootPathName: string; lpVolumeNameBuffer: string; nVolumeNameSize: DWORD;
var lpVolumeSerialNumber: DWORD; var lpMaximumComponentLength: DWORD;
var lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: string;
nFileSystemNameSize: DWORD): BOOL;
external 'GetVolumeInformationW@kernel32.dll stdcall';
const
MAX_PATH = 260;
function FindVolumeName(const Drive: string): string;
var
FileSystemFlags: DWORD;
VolumeSerialNumber: DWORD;
MaximumComponentLength: DWORD;
begin
SetLength(Result, MAX_PATH)
if GetVolumeInformation(
Drive, Result, Length(Result), VolumeSerialNumber, MaximumComponentLength,
FileSystemFlags, '', 0) then
begin
SetLength(Result, Pos(#0, Result) - 1);
end
else
begin
RaiseException(SysErrorMessage(DLLGetLastError()));
end
end;
(The code is for Unicode version of Inno Setup – The only version as of Inno Setup 6). (代码适用于 Inno Setup 的 Unicode 版本——Inno Setup 6 的唯一版本)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.