How to embed a DLL within a C++/CLI executable?

安稳与你 提交于 2019-12-24 11:04:59

问题


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!


回答1:


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:

  • 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?



回答2:


Thanks for repply. The architecture of my project require that the WPF assembly is a DLL (not my choice ^^)

[SOLVED] I have found a solution by using thses tow topics that I havn't saw before : embed DLL in MFC C++ EXE? Loading interdependent assemblies from C++/CLI

Now the WPF is embedded in the rc file, and I can load it without adding it as reference. Thank you !



来源:https://stackoverflow.com/questions/23605048/how-to-embed-a-dll-within-a-c-cli-executable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!