【发布时间】:2020-03-05 13:13:06
【问题描述】:
我从 Inno Setup Script 中的 DLL 文件调用一个函数,它的返回类型是 PAnsiChar。
为了获得整个字符串,我需要取消引用指针,但标准的帕斯卡语法在这里不起作用。
甚至有可能做到这一点吗?
function SQLDLL : PAnsiChar;
external 'GetSQLServerInstances@files:IsStartServer.dll stdcall setuponly';
function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd: Integer;
Str : AnsiString;
begin
if CurPage = wpWelcome then begin
hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
MessageBox(hWnd, 'Hello from Windows API function', 'MessageBoxA', MB_OK or MB_ICONINFORMATION);
MyDllFuncSetup(hWnd, 'Hello from custom DLL function', 'MyDllFunc', MB_OK or MB_ICONINFORMATION);
Str := SQLDLL;
try
{ if this DLL does not exist (it shouldn't), an exception will be raised }
DelayLoadedFunc(hWnd, 'Hello from delay loaded function', 'DllFunc', MB_OK or MB_ICONINFORMATION);
except
{ handle missing dll here }
end;
end;
Result := True;
end;
我只有 DLL 文件。原始语言是 Delphi。
我更新到最新版本的 Inno Setup 6.0.3 并在我的家用 Windows 10 Pro 机器上测试了此代码:
[Setup]
AppName=My Program
AppVersion=1.5
WizardStyle=modern
DefaultDirName={autopf}\My Program
DisableProgramGroupPage=yes
DisableWelcomePage=no
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
Source: "IsStartServer.dll"; Flags: dontcopy
[Code]
function SQLDLL : PAnsiChar;
external 'GetSQLServerInstances@files:IsStartServer.dll stdcall';
function NextButtonClick(CurPage: Integer): Boolean;
var
Str : PAnsiChar;
begin
Str := SQLDLL;
Result := True;
end;
我不明白为什么它必须查看我的“临时”目录?我还听说这个问题可能与 Windows 10 UAC 中的组策略有关,但我不确定我应该在这里做什么来消除这个错误。
【问题讨论】:
-
我试图将我的代码作为文本发布,但字符太多,所以我无法这样做。
-
但是你需要有函数声明(= API 规范)。这是什么?
-
函数 GetSQLServerInstances: PAnsiChar;
-
它是否声明为
stdcall(不确定它是否对无参数函数有影响)。 – 除此之外,我相信我的回答显示了正确的解决方案。您可以使用任何其他语言的 DLL 检索完整的字符串吗? -
顺便说一句,您是否在最新版本的 Inno Setup 中对此进行了测试? (因为您使用的是一些过时的)
标签: pointers inno-setup dereference pascalscript