我无法调用几个 Windows API 来安装驱动程序。具体来说:
SetupCopyOEMInf或DriverPackageInstall
我使用的原型似乎不起作用,可能是由于 Unicode 字符串或使用了指针。注意:我使用的是 Inno Setup 的 Unicode 版本。有些参数可能是NULL,但我不知道如何在Code部分指定NULL。
以下是我尝试过的原型:
function SetupCopyOEMInf(SourceInfFileName: String;
OEMSourceMediaLocation: String; OEMSourceMediaType: Longword;
CopyStyle: Longword; DestinationInfFileName: String;
DestinationInfFileNameSize: Longword; var RequiredSize: Longword;
DestinationInfFileNameComponent: String): Longword;
external 'SetupCopyOEMInfW@setupapi.dll stdcall setuponly';
function GetLastError(): Longword;
external 'GetLastError@kernel32.dll stdcall setuponly';
type
InstallerInfo = record
pApplicationId: String;
pDisplayName: String;
pProductName: String;
pMfgName: String;
end;
function DriverPackageInstall(DriverPackageInfPath: String;
Flags: Longword; pInstallerInfo: InstallerInfo;
var pNeedReboot: Longword): Longword;
external 'DriverPackageInstall@files:difxapi.dll stdcall setuponly';
原型可能是正确的,但我遇到了不同的错误,我不知道。我知道出了点问题,因为调用失败(返回失败代码)并且从 C 程序进行相同的调用工作正常。
更新1:
DriverPackageInstall
可能不会立即有用。DLL 必须在使用前注册。并不是说这是不可能的,只是需要比这个问题更多的工作。
更新 2、3:
示例用法:
const
MAX_PATH = 260;
SPOST_PATH = 1;
SP_COPY_DELETESOURCE = $0000001;
procedure InstallUsbDriver();
var
RequiredSize: DWORD;
DestinationInfFileName: String;
DestinationInfFileNameComponent: String;
begin
SetLength(DestinationInfFileName, MAX_PATH);
SetLength(DestinationInfFileNameComponent, MAX_PATH);
if not SetupCopyOEMInf(ExpandConstant('{app}\driver.inf'),
ExpandConstant('{app}'), SPOST_PATH, SP_COPY_DELETESOURCE,
DestinationInfFileName, MAX_PATH, RequiredSize,
DestinationInfFileNameComponent) then begin
MsgBox('Error installing USB driver: ' + SysErrorMessage(DLLGetLastError),
mbError, MB_OK);
CancelWithoutPrompt := True;
WizardForm.Close;
end;
end;