我可以在 C++/CLI dll 中重写 _matherr 吗?
我有一个非托管 C++ 应用程序,它提供自定义 _matherr 处理程序。当此应用程序加载并运行非托管 DLL 中的代码时,如果存在数学错误(例如 asin(100.0)),则会调用自定义 _matherr 函数并且一切正常。
但是,我现在尝试在 C++/CLI 中创建一个 NUnit 测试 DLL,它加载相同的非托管 DLL 并运行与上述应用程序相同的代码。我想要做的是将 _matherr 函数添加到 C++/CLI dll 中,以便在发生数学错误时我可以执行一些自定义处理程序逻辑。
C++/CLI dll 使用定义的 _matherr 函数编译得很好,但是当我强制非托管 dll 出现数学错误时,不会调用 _matherr 函数。
C++/CLI 不支持吗? MSDN 文档似乎说 _matherr 受所有 C 运行时支持(带有指向运行时列表的链接,包括 /clr 运行时。)
I have an unmanaged c++ application that provides a custom _matherr handler. When this application loads and runs code in unmanaged DLLs, if there is a Math error ( e.g. asin( 100.0 ) ) the custom _matherr function is called and everything works.
However, I'm now trying to create a NUnit Test DLL in C++/CLI that loads the same unmanaged DLL and runs the same code as the application above. What I want to do is add the _matherr function to the C++/CLI dll such that when math errors occur I can perform some custom handler logic.
The C++/CLI dll compiles just fine with the _matherr function defined, but when I force a math error from the unmanaged dll, the _matherr function is not called.
Is this not supported by C++/CLI? The MSDN documentation seems to say _matherr is supported by all C Run times, (with a link to a list of runtimes including the /clr runtime. )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的经验是,如果在 dll 中定义 _matherr 则不起作用。它必须在可执行文件中定义。
我什至见过编译器,当您尝试在 dll 中添加 _matherr 时,它不会链接它,因为它们看不到任何人对其进行引用。
My experience is that defining _matherr does not work if done in a dll. It must be defined in the executable.
I've even seen compilers that when you try to add _matherr in a dll, will not link it in because they don't see anybody making a reference to it.
也许您需要像代理 dll 这样的东西,将每个函数调用传递给原始 dll,除了那些您想要额外处理的函数。
Maybe you need something like a proxy dll, passing through each function call to the original dll excepting those you want to be handled extra.