小编kao*_*soe的帖子

在 Alexandria 64 位中调用 OpenSCManager 进行范围检查

我们最近从 Delphi Berlin 更新到 Alexandria 11.2,并遇到了问题。我们的应用程序之一针对 64 位平台。当它连接查询 Windows 服务时,它会抛出范围检查错误。当以 32 位为目标时,它不会执行此操作;柏林/64 位也没有发生这种情况。我比较了两种环境之间的 64 位编译选项,没有发现任何差异。

function TForm1.ConnectToServices(const AServiceName: String; const AMachineName: String): Integer;
begin
  Result := -1;
  try
    if AMachineName = EmptyStr then
      // Error happens here
      Result := OpenSCManager(nil, nil, SC_MANAGER_CONNECT)
    else
      // and here.
      Result := OpenSCManager(PChar(AMachineName), nil, SC_MANAGER_CONNECT);
  except
    // Get last error return 0, but ignoring the above error causes problems downstream
    ShowMessage(SysErrorMessage(GetLastError));
  end;
end;
Run Code Online (Sandbox Code Playgroud)

我真的不知道是什么原因造成的以及如何解决它。

设置 64 位编译器选项以匹配 Berlin 的编译器选项,其中 dll 调用成功且没有问题。

delphi 64-bit winapi range-checking delphi-11-alexandria

3
推荐指数
1
解决办法
126
查看次数