如何将Win32 API应用程序部署为可执行文件 [英] How to deploy a Win32 API application as an executable

查看:172
本文介绍了如何将Win32 API应用程序部署为可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Win32应用程序部署为EXE应用程序,以便其他人(未安装VC ++)可以使用它?

How can I deploy my Win32 application as an EXE application so that others (who don't have VC++ installed) can use it?

我正在Windows 7上使用VC ++ 2010.

I am using VC++ 2010 on Windows 7.

推荐答案

如果在编译完成的程序时切换到发布"模式(而不是在开发过程中用于调试它的调试"),则应该获取将在未安装Visual Studio的计算机上运行的可执行文件.

If you switch to "Release" mode when you compile your finished program (rather than "Debug", which you use for debugging it during development), you should get an executable that will run on a computer without Visual Studio installed.

但是,该可执行文件仍将需要安装适当版本的C运行时库.例如,如果您是在Visual C ++ 2010中开发的,则将需要安装CRT的版本10.这是一个可免费重新分发的库,可在此处下载.

However, that executable will still require the appropriate version of the C runtime library to be installed. For example, if you developed it in Visual C++ 2010, you will need version 10 of the CRT installed. This is a freely redistributable library, downloadable here.

因此,您有几个部署选项:

So, you have several options for deployment:

  1. 手动部署

给人裸露的可执行文件,并将可重新分发的安装程序包括在安装介质上的另一个文件夹中.如果他们将可执行文件复制到磁盘并且由于收到错误消息而无法运行,则应从随附的可再发行安装程序中安装CRT库.然后可执行文件就可以正常运行了.

Give people the bare executable file, and include the installer for the redistributable in another folder on the installation media. If they copy the executable to disk and cannot run it because they get an error message, they should install the CRT libraries from the included redistributable installer. Then the executable will run just fine.

如果您具有相对精通计算机的读者,或者您正在部署到固定范围的计算机(例如整个学校或公司),则此方法非常有用.但是,对于一般部署到客户来说,效果并不理想.

This works great if you have relatively a computer-savvy audience, or you're deploying to a fixed range of machines (like across a school or corporation). But it doesn't work so well for general deployment to customers.

实际上,您甚至不需要安装程序.您只需将CRT DLL与可执行文件放在同一文件夹中,它就可以正常运行.这就是我测试在干净VM上开发的应用程序的方式.它像一种魅力.完全不需要运行CRT安装程序.您将在Visual Studio安装中找到这些必需的库:

In fact, you don't even need the installer. You can just place the CRT DLLs in the same folder as your executable and it will run just fine. This is how I test apps I'm developing on clean VMs. It works like a charm. There's no need to run the CRT installer at all. You'll find these required libraries as part of your Visual Studio installation:

<Program Files folder>\Microsoft Visual Studio 10.0\VC\redist\x86

  • 自动部署

    创建一个安装程序,该程序将自动安装您的应用程序以及所需的任何依赖项,包括可再发行的CRT.这就是您看到的大多数商业应用程序正在做的事情.除了最琐碎的应用程序之外,我都建议使用它.

    Create a setup program that automatically installs your application along with any dependencies it requires, including the CRT redistributable. This is what you see most commercial applications doing. I recommend it for anything but the most trivial of apps.

    Visual Studio 2010的完整版本(即非Express版本)可以创建一个安装项目,您可以根据需要自定义该项目以用作应用程序的安装程序.但这不再是创建安装程序的推荐方法,并且此功能

    Full versions of Visual Studio 2010 (i.e., not Express versions) can create a Setup Project that you can customize as needed to work as an installer for your application. But this is no longer the recommended way to create an installer, and this functionality has been removed from the latest version of Visual Studio, 2012.

    因此,即使您有安装项目可用的VS较旧版本,我也建议您使用其他方法.浪费时间来创建某些东西,以后只需要更新就没有意义了.我个人最喜欢的用于创建安装程序的选择是 WiX

    So I recommend using something else, even if you have an older version of VS where the Setup Project is available. No point in wasting time creating something you'll just have to update later. My personal favorite choices for creating setup programs are WiX and Inno Setup. Both are free, and extensive documentation is available online.

    创建不需要做很多事情的简单设置确实非常简单-对您来说可能就是这种情况,因为您需要做的就是安装CRT可再发行组件(如果尚未安装的话).我愿意打赌,您可以在WiX或Inno设置程序中在线找到演练或示例来了解如何操作.

    Creating simple setups that don't have to do very much is really quite straightforward—this is likely the case for you, as all you need to do is install the CRT redistributable if it is not already there. I'd be willing to bet money you can find a walkthrough or example online for how to do this in either WiX or Inno Setup.

    如果您需要做更复杂的事情,这两个安装程序包都支持它.它们具有广泛的可定制性,并且功能非常强大,只需花更多的工作就可以完成.

    If you need to do more complicated stuff, both of these setup packages support it. They are extensively customizable and very powerful, it just takes more work to get it all going.

    静态链接

    如果绝对需要分发一个保证双击即可正常工作的裸可执行文件,则需要在所需的运行时库中将项目切换为静态链接.这意味着链接器实际上将所有CRT代码实际上直接嵌入到您的可执行文件中,并且意味着您不必单独重新分发CRT库.

    If you absolutely need to be able to distribute a bare executable that is guaranteed to simply work when double-clicked, you will need to switch your project to statically link in the required runtime libraries. This means that all of the CRT code is actually embedded by the linker directly into your executable, and means that you don't have to redistribute the CRT libraries separately.

    此方法的缺点是,从CRT发布的改进,错误修复和安全补丁中受益的唯一方法是重新编译和重新分发您的应用程序.如果您动态链接(默认设置),则您的应用将自动受益于CRT库已安装版本的增强功能. Microsoft强烈建议反对静态链接.

    The disadvantage of this approach is that the only way to benefit from improvements, bug fixes, and security patches released for the CRT is to recompile and redistribute your application. If you dynamically link (the default), your app will automatically benefit from enhancements to the installed version of the CRT libraries. Microsoft strongly recommends against static linking.

    要在Visual Studio中的这些模式之间切换,请按照下列步骤操作:

    To switch between these modes in Visual Studio, follow these steps:

    • 在解决方案资源管理器中右键单击您的项目,然后选择属性".
    • 确保在对话框顶部的下拉框中选择了发布"配置.
    • 在TreeView中展开"C/C ++"项,然后选择代码生成".
    • 将运行库"选项的设置更改为多线程(/MT)".

    最终说明:不能重新分发CRT库的调试"版本,但这没关系,因为您应该始终分发以下版本的发布"版本无论如何都是您的应用,永远不要使用调试"版本.

    Final Note: The "Debug" versions of the CRT libraries are not redistributable, but that doesn't matter because you should always distribute the "Release" build of your app anyway, never the "Debug" build.

    这篇关于如何将Win32 API应用程序部署为可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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