避免在 C++/CLI 项目中加载 .Net Dll?

发布于 2024-08-06 19:30:54 字数 369 浏览 3 评论 0原文

我有一个用 C++/CLI 编写的项目。有些类型存在于托管代码中,有些类型存在于完全本机代码中。假设我在一台没有安装任何版本的 .Net 框架的机器上生成了 DLL,有没有办法让另一个本机应用程序与我的“混合模式”Dll 链接并仅使用本机类型?我注意到,在我添加“/clr”开关的那一刻,我的 Dll 自动依赖于几个 .Net Framework Dll(mscorjit、mscoree 等),并且当我实际尝试使用其中定义的 100% 本机类型时,应用程序仍然尝试加载这些 .Net Framework Dll(即使我在这部分代码中没有使用该框架)。
那么,在这种情况下是否可以避免加载这些 Dll 呢? (在我看来,另一个选择是创建另一个本机项目,它将包含所有本机类型,而不包含托管类型)。

谢谢

I have a project written in C++/CLI. Some of the types there are in managed code, and some are in completely native code. Let's say I have the produced DLL on a machine that dosen't have any version of the .Net framework installed, is there a way that another, native application will link with my "mixed-mode" Dll and use only the native types? I've noticed that the minute I add the "/clr" switch, my Dll automatically depends on several .Net Framework Dlls (mscorjit, mscoree etc.), and when I actually try to use the 100% native types defined in it, the application still tries to load those .Net Framework Dlls (even though I don't use the framework in that part of the code).
So, is it possible to avoid loading those Dlls in such case? (as I see it, the other option is to create another, native project, that will contain all of the native types, without the managed ones).

Thanks

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

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

发布评论

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

评论(1

以可爱出名 2024-08-13 19:30:54

不会。当您加载混合模式程序集 (/clr) 时,在 DllMain 运行之后,.cctor 会立即运行并初始化框架(如果尚未为应用程序设置框架)。

如果没有这个,一旦您调用需要托管 API 的函数,就会受到很大的影响。有关详细信息,请参阅 MSDN 上的“混合程序集的初始化”。

最好的选择是使您的本机 API 成为一个单独的 DLL,并将混合模式程序集作为一个单独的项目,以便您可以根据需要单独加载它。

No. When you load a mixed mode assembly (/clr), right after DllMain runs, the .cctor runs and initializes the framework, if it hasn't already been setup for the application.

Without this, there would be a big hit as soon as you called a function that required a managed API. For details, see "Initialization of Mixed Assemblies" on MSDN.

The best option would be to make your native API a separate DLL, and have the mixed mode assembly a separate project, so you can load it separately if required.

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