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

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

问题描述

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

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.

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

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).

我想我必须创建一个资源文件,但我从来没有使用过这种类型的文件,我有点失落,因为在资源文件中嵌入一个DLL是不直观的。

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!

推荐答案

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

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

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

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

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

#using <datei.netmodule>

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

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

另请参见:

  • http://blogs.msdn.com/b/texblog/archive/2007/04/05/linking-native-c-into-c-applications.aspx
  • How to link C# and C++ assemblies into a single executable?

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

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