Inno Setup 6不能在字符串参数中使用DLL函数,而可以在Inno Setup 5中使用

基拉

我们当前正在使用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; 

  ...
}
马丁·普里克里(Martin Prikryl)

这不是5.x vs 6.x问题,也不是位问题。这是Ansi与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 Setup以字符串为参数调用DLL

另请参见从Ansi升级到Inno Setup的Unicode版本(任何缺点)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章