[英]Embed one exe into another in order to build a single exe?
I have a Winforms project and a console project.我有一个 Winforms 项目和一个控制台项目。
I was starting the console app from the Winforms app as an external process, but would like to compile both into a single exe, if possible.我从 Winforms 应用程序启动控制台应用程序作为外部进程,但如果可能的话,我想将两者编译成一个 exe。
I have brought them both into a single VS 2015 solution.我将它们都带入了一个 VS 2015 解决方案中。 Should I be able to accomplish this by converting the console app to a library?
我是否可以通过将控制台应用程序转换为库来完成此操作?
Aside from all the reference, dependency and linker settings/paths, how would I pass the command line arguments to, and start the console app from the Winforms code.除了所有引用、依赖项和链接器设置/路径之外,我将如何将命令行参数传递给 Winforms 代码并从 Winforms 代码启动控制台应用程序。 ie jump to the entry point of the console app?
即跳转到控制台应用程序的入口点? The solution builds OK so far.
到目前为止,该解决方案构建正常。
Yes, a library is the right approach.是的,图书馆是正确的方法。 If you want one exe, you'll want to link it as a static library.
如果您想要一个 exe,您需要将它链接为一个静态库。
After converting the project to a library, change the "main" function to use a different name, I will use "foobar" for example.将项目转换为库后,将“main”函数更改为使用不同的名称,例如我将使用“foobar”。
If your Winforms project is C++ as well, next create an h file that has the definition for the "foobar" function, eg:如果您的 Winforms 项目也是 C++,接下来创建一个具有“foobar”函数定义的 h 文件,例如:
int foobar(int argc, char *argv[]);
This will be your library's external interface.这将是您图书馆的外部接口。 Simply include it, and then you can call it:
只需包含它,然后您就可以调用它:
const char *argv[] = {"progname", "arg1", "arg2"};
int result = foobar(3, argv);
Of course, you can also change this function to take more convenient arguments.当然,您也可以更改此函数以使用更方便的参数。 Remember that, by default, argv[0] is the program name and is probably ignored.
请记住,默认情况下, argv[0] 是程序名称,可能会被忽略。
If you're using C# or otherwise can't include the .h directly, I'm not sure if this is possible.如果您使用 C# 或不能直接包含 .h,我不确定这是否可行。 See here:
看这里:
How to compile C# application with C++ static library? 如何使用 C++ 静态库编译 C# 应用程序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.