我们目前正在使用Inno安装版本5.5.3来构建一个安装程序。我计划将这个版本升级到6.1.2。
我们使用Inno设置来安装我们的产品。我们随安装程序一起发布许可证代码,用户在安装过程中在字段中输入许可证。此许可证使用自定义DLL进行验证,DLL将返回非负结果以获得有效许可。此过程在5.5.3和5.6.1中运行良好,但在版本6(使用6.0.5和6.1.2进行测试)中失败。
不幸的是,没有生成任何日志,这正是问题所在。
这个自定义DLL是32位的,是在10年前使用C++构建的.没有重播这个部分的计划。是否有任何方法使用相同的DLL并修复此问题?谢谢。
[Files]
Source: mydll.dll; Flags: dontcopy// This function calls the external mydll which parses licenseCode and
// returns an integer
function getFlags( secret, licenseCode : String) : Integer;
external 'getFlags@files:mydll.dll cdecl';function checkLicense(license : String) : Boolean;
var
secret : String;
begin
Result := False; // default is Incorrect license
license := Trim(license);
secret := <secret>
// This line calls the above getFlags function and expects to get an integer
license_flags := getFlags( secret, license);
if license_flags = -1 then begin
if not suppressMsgBox then begin
MsgBoxLog( ‘Incorrect License’)
end;
Exit;
end;
Result := True;
end;// This is the c++ function
PS_EXPORT(int) getFlags( const char * secret, const char * license ) {
// This function is returning -1 for Inno Setup 6
// but works fine for Inno Setup 5
if (strlen(license) == 0)
return -1;
...
}发布于 2020-12-02 21:24:52
这不是5.x对6.x问题,也不是bitness问题。这是Ansi与Unicode之间的问题。
在5.x中,有两个版本的Inno安装程序,Ansi版本和Unicode版本。您可能在使用Ansi版本,您的代码就是为此设计的。在6.x中,只有Unicode版本。您的代码在Unicode版本中不工作。通过升级到6.x,您无意中也从Ansi升级到Unicode。
一个快速而肮脏的解决方案是更改getFlags函数的声明,以正确声明参数为Ansi字符串(AnsiString类型):
function getFlags( secret, licenseCode : AnsiString) : Integer;
external 'getFlags@files:mydll.dll cdecl';正确的解决方案是重新实现DLL以使用Unicode字符串(wchar_t指针):
PS_EXPORT(int) getFlags( const wchar_t * secret, const wchar_t * license )这是一个类似的问题:Inno Setup Calling DLL with string as parameter。
另见Upgrading from Ansi to Unicode version of Inno Setup (any disadvantages)。
https://stackoverflow.com/questions/65115997
复制相似问题