在非托管 DLL 中调用方法时,如何保护我的 C# 应用程序免于崩溃?

发布于 2024-09-08 10:47:51 字数 152 浏览 1 评论 0原文

我有一个由另一位开发人员用非托管 C++ 编写的非托管 DLL。我的应用程序是用 C# 编写的 WinForms 应用程序。我正在使用互操作来调用本机 DLL 中的方法(函数)。该调用导致我的应用程序在执行该方法时崩溃。

如何使用互操作安全地调用方法,以免导致应用程序崩溃?

I have an unmanaged DLL written by another developer in unmanaged C++. My application is a WinForms application written in C#. I am using interop to call a method (function) in the native DLL. The call is causing my application to crash upon executing the method.

How does one safely call a method using interop, so that it does not bring the app down?

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

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

发布评论

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

评论(1

终难愈 2024-09-15 10:47:51

您可以创建一个单独的 AppDomain 并在其中加载非托管 DLL。如果调用崩溃,它只会使 AppDomain 崩溃,并且您的应用程序仍然存在

You could create a seperate AppDomain and load the unmanaged DLL in it. If the call crashes, it will just crash the AppDomain and your application will still live

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文