如何构建 C++ 运行在带有 Visual Studio 2008 的普通 XP SP2 上并且没有并排 DLL 的应用程序?

发布于 2024-07-16 03:40:08 字数 482 浏览 5 评论 0原文

我想通过一次调用 WinExec 来编译一个 C++ 项目,以便使用一些命令行参数启动另一个可执行文件。 我不知道要在我的项目中指定哪些设置才能生成不需要 Microsoft 并行 DLL 的可执行文件,而我不想将其安装在我的目标系统上。 有什么提示吗?

症状是应用程序无法启动,并且以下事件被写入应用程序日志(从法语免费翻译):

Error, SideBySide, event #33
Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" cannot be found. 

更新:我知道使用 WinExec 是不好的做法,但它有效就像一个魅力,微软不可能在 API 的任何未来版本中删除它,不是吗?

I'd like to compile a C++ project with just a single call to WinExec in order to launch another executable with some command line parameters. I've no idea what settings to specify in my project in order to get produce an executable that works without requiring Microsoft side-by-side DLLs, which I don't want to have to install on my target system. Any hints?

The symptom is an application which fails to start and the following event getting written to the application log (freely translated from French):

Error, SideBySide, event #33
Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" cannot be found. 

UPDATE: I know that using WinExec is bad practice, but it works like a charm, and Microsoft can't possibly remove it in any future release of the API, can't they?

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

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

发布评论

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

评论(3

抱着落日 2024-07-23 03:40:08

如果您指定要静态链接运行时(/MT 或 /MTd),那么应该没问题。 项目属性->C/C++->代码生成->运行时库

If you specify that you want to statically link the run-time (/MT or /MTd) you should be good. Project Properties->C/C++->Code Generation->Runtime Library

汐鸠 2024-07-23 03:40:08

如果您需要的只是 CreateProcess/ShellExecute(WinExec 自 NT 3.1/Win 95 起已弃用),则根本不需要任何运行时库。 在项目属性/配置/链接器/输入中启用忽略所有默认库并将kernel32.lib添加到其他依赖项

If all you need is CreateProcess/ShellExecute (WinExec is deprecated since NT 3.1/Win 95), you don't need any runtime library at all. In Project Properties / Configuration / Linker / Input enable Ignore All Default Libraries and add kernel32.lib to Additional Dependencies.

你的笑 2024-07-23 03:40:08

jachymko 和 Josh 都(部分)回答了该解决方案。 这是完整的解决方案:

  1. 项目属性/配置/链接器/输入/忽略所有默认库设置为并添加kernel32.lib其他依赖项。 仅此一项不会链接,因为代码会自动引用 __security_check_cookie_WinMainCRTStartup

  2. 删除/GS开关以指示编译器不要注入安全检查代码。 为此,请将项目属性/配置/C/C++/代码生成/缓冲区安全检查设置为

  3. 项目属性/配置/C/C++/代码生成/运行时库设置为多线程(/MT)

  4. 最初的 Visual Studio 2008 生成的代码包含一个名为 _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)入口点。 通过重命名它来修改它 WinMain 并将第三个参数转换为 LPSTR

  5. 项目属性/配置/链接器/高级/入口点设置为WinMain

通过对默认 C++ 项目进行这些更改,代码最终可以编译和链接,并在新安装的 Vista 或 XP(缺少运行时库)上运行。

The solution has been answered (partially) by both jachymko and Josh. Here is the full solution:

  1. Set Project Properties / Configuration / Linker / Input / Ignore All Default Libraries to Yes and add kernel32.lib to Additional Dependencies. This alone won't link, as the code automatically refers to __security_check_cookie and _WinMainCRTStartup.

  2. Remove /GS switch to instruct the compiler not to inject the security check code. For this, set Project Properties / Configuration / C/C++ / Code Generation / Buffer Security Check to No.

  3. Set Project Properties / Configuration / C/C++ / Code Generation / Runtime Library to Multi-threaded (/MT).

  4. The initial Visual Studio 2008 generated code contains an entry point named _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int). Modify it by renaming it WinMain and convert the third argument to LPSTR.

  5. Set Project Properties / Configuration / Linker / Advanced / Entry Point to WinMain.

With these changes to a default C++ project, the code finally compiles and links, and runs on a freshly installed Vista or XP, which lacks the runtime library.

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