系统算术异常:Delphi 通过 C++/CLI 包装器调用 C# DLL

发布于 2024-08-05 03:19:45 字数 616 浏览 4 评论 0原文

我有一个 C# DLL,它使用 XslCompiledTransform 类进行 xml 操作。我窃取了 C# DLL 的 C++/CLI 包装器。

当使用 Delphi 5 实现 C++/CLI 包装器时,我收到系统算术错误。下面是 Delphi 5 声明:

procedure XsltMethod(XmlPath, XsltPath: PWideChar); cdecl; external 'ahma.dll';

C# 公共方法的主体创建了一个新的 XslCompiledTransform 对象,并且当新创建的对象运行其 load 方法时,会立即弹出异常。例如:

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XsltFile);

如前所述,.NET DLL 抛出的异常是系统算术异常。仅当从 Delphi 可执行文件调用时才会发生这种情况。

我想我应该提到再次调用对象的 load 方法效果很好。因此,捕获异常并运行该方法进行第二次“传递”就像弹出窗口阻止程序一样。当然,也有例外。

I have a C# DLL that uses the XslCompiledTransform class for xml manipulations. I stole a C++/CLI wrapper for the C# DLL.

When using Delphi 5 to implement the C++/CLI wrapper, I receive a System Arithmetic error. Here is the Delphi 5 declaration:

procedure XsltMethod(XmlPath, XsltPath: PWideChar); cdecl; external 'ahma.dll';

The body of the C# public method creates a new XslCompiledTransform object and the exception pops up right when the newly created object runs its load method. For example:

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XsltFile);

As mentioned earlier, the exception thrown from the .NET DLL is a System Arithmetic Exception. This only happens when called from a Delphi executable.

I guess I should mention calling the object's load method again works fine. So catching the exception and running the method for a second "pass" acts like a popup blocker. But for exceptions, of course.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南汐寒笙箫 2024-08-12 03:19:45

也许您会遇到浮点控制寄存器的差异,如此处所述。另请参阅质量控制报告。您可以尝试拨打 Set8087CW($133F);在您的 Delphi 程序中。此后请小心 Delphi 代码中的浮点问题。

Maybe you suffer from differences in the Floating-Point Control Register as stated here. Also see this QC report. You could try calling Set8087CW($133F); in your Delphi program. Be cautious of floating point problems in your Delphi code after that.

随机想法:

  • 我认为您应该从 Visual Studio 调试程序集开始。在 Delphi 代码中插入消息框或其他等待语句,然后从 Visual Studio 附加到进程。跟踪 C# 可能会提供一些有关问题所在的提示。如果你不能让它工作,至少添加传入参数的日志记录。
  • 在delphi中,你不需要转义反斜杠。
  • 您确定 E0434F4D 不是一些无辜的第一次机会异常吗?如果您不进行调试(或者从 JIT 调试器异常停止处继续,我不完全确定 Delphi 5 是否可以这样做),那么该行为确实有错误吗?
  • 我们能否将“本机 Win32 程序集”称为“DLL”,就像过去 20 年来我们对它们的称呼一样? :-)

Random thoughts:

  • I think you should start by debugging your assembly from Visual Studio. Insert a messagebox or other wait statement in the Delphi code, then attach to process from Visual Studio. Tracing the C# might provide a couple of hints on what is going wrong. If you can't get it working, at least add logging of the incoming parameters.
  • In delphi, you don't need to escape backslashes.
  • Are you sure the E0434F4D is not some innocent first-chance exception? If you do not debug (or continue from the JIT debugger exception stop, which I'm not entirely sure is possible with Delphi 5), is the behaviour indeed faulty?
  • Could we please refer to "native Win32 assembly" as "DLL", like we used to call them for the past 20 years? :-)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文