我们目前正在使用Inno Setup版本5.5.3来构建安装程序。我打算将此版本升级到6.1.2。
我们使用Inno Setup来安装我们的产品。我们将许可证代码与安装程序一起提供,并且用户在安装过程中在字段中输入许可证。使用自定义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;
...
}
这不是5.x vs 6.x的问题,也不是位数问题。这是Ansi vs. Unicode问题。
在5.x中,有两个版本的Inno Setup: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安装程序以字符串作为参数调用DLL。
我无法将unicode版本与我的问题相关联,现在已经很清楚了。谢谢你。