如何在C ++ / CLI可执行文件中嵌入DLL? [英] How to embed a DLL within a C++/CLI executable?

查看:227
本文介绍了如何在C ++ / CLI可执行文件中嵌入DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个C ++ / CLI项目中,我试图在我的可执行文件中嵌入一些DLL文件(WPF自定义控件库),以避免在同一个文件夹中有超过9000个DLL。
有很多关于在C#项目中嵌入C ++ / CLI DLL的信息(此外,它非常简单),但有关反向的文档似乎很差。



我找到的最接近的解决方案是:将资源嵌入到C ++ / CLI项目,但不幸的是,当我使用Visual Studio(2008或2012)打开.exe文件时,我无法看到我的WPFWidget.dll资源。



我想我必须创建一个资源文件,但我从来没有使用过这样的文件,而且我有点迷失,因为在一个资源文件中嵌入一个DLL对我来说并不直观。



你知道一个可以帮助我的方法吗?谢谢!

解决方案

我建议您用命令行编译C#代码并创建一个.net模块:

  csc / target:module /addmodule:mfoo.obj bar.cs 

然后,您可以将其合并到C ++ / CLI代码中与

  #using< ; datei.netmodule> 

链接/ LTCG。所以你只有一个C ++ / CLI DLL,所有的C#代码里面...



另请参见:




I'm on a C++/CLI project, and I'm trying to embed some DLL files (WPF custom control library) within my executable to avoid having over 9000 DLLs in the same folder. There is a lot of information about embedding a C++/CLI DLL in a C# project (moreover, it is very simple), but the documentation about the reverse seems to be poor.

The closest solution I have found is here: Embedding resource in a C++/CLI project, but unfortunately I can't see my WPFWidget.dll in resources when I open the .exe file with Visual Studio (2008 or 2012).

I suppose I have to create a resource file, but I have never used this kind of file, and I'm a little lost because embedding a DLL in a resource file isn't intuitive to me.

Do you know a proper method which could help me? Thanks!

解决方案

I suggest you compile your C# code with command line and create a .net module:

csc /target:module /addmodule:mfoo.obj bar.cs

Then you can merge this into the C++/CLI code with

#using <datei.netmodule>

Link with /LTCG. So you have only one C++/CLI DLL, with all the C# code inside...

See also:

这篇关于如何在C ++ / CLI可执行文件中嵌入DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆