4

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

I am using VC++ 2010 on Windows 7.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Apoorv
  • 373
  • 1
  • 5
  • 15
  • I assume you do not want the other computer to install runtime libraries? Are you using the Express edition of vc++ 2010? – Floris Velleman Apr 18 '13 at 12:44
  • 1
    VC++ Express does not contain Windows Installer code creation, and just copy-dropping executables in Windows is generally considered bad-form. You ideally need to create an MSI package that contains your program, along with other information (like where it installs, what platforms it supports, registry keys i requires, etc). Since VC++ Express doesn't include this by default, consider using the [Windows Installer SDK](http://msdn.microsoft.com/en-us/library/windows/desktop/aa370834%28v=vs.85%29.aspx) – WhozCraig Apr 18 '13 at 12:59

3 Answers3

7

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.

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. Manual Deployment

    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.

    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
    
  2. Automated Deployment

    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.

    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.

    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.

    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.

  3. Static Linking

    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.

    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.

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

    • Right-click on your project in the Solution Explorer and select "Properties".
    • Ensure that the "Release" configuration is selected in the drop-down box at the top of the dialog.
    • Expand the "C/C++" item in the TreeView, and select "Code Generation".
    • Change the setting of the "Runtime Library" option to "Multi-threaded (/MT)".

    A further description on what these cryptic compiler switches mean and which ones you should use when is given in my answer here.

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.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • I have already created .EXE file and its working fine but it does not have Uninstaller.exe file in my Release Build folder. So can you please provide me how to create or generate uninstaller.exe in this release folder, and after installing my game.exe file to other computer it is not sowing on Controle panel Please help. thanks. @CodyGray – Manoj Kumar Rai Aug 05 '19 at 07:19
1
  1. In general, the odds are pretty good your EXE file will run on any version of Windows you built it on or higher.

    All bets off, for example, if you built using Visual Studio 2012 Professional on Windows 7, and you try to run it on Windows 95. But otherwise, you're probably safe :)

  2. The best way to test if you have any dependencies is to install and run on a "clean machine".

    The best way to get (and reuse) a "clean machine" is with a VM. I recommend VMWare. But Virtual Box and Windows Virtual PC are also viable choices.

  3. As far as an installer, I'd strongly encourage you to look at Inno Setup

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Number 1 is only true if you statically link to the CRT. Otherwise, the appropriate version to match your compiler must be installed on the machine. You cannot simply assume that this will be the case. You're responsible for bundling your own dependencies. And I know the Windows 95 thing was a joke, but the oldest version of Windows that apps compiled with the VS 2010 toolset will run on is Windows XP. Windows 2000 is not supported. – Cody Gray - on strike Apr 19 '13 at 02:58
  • Good advice on using VMs for testing, though. I personally use Virtual Box. – Cody Gray - on strike Apr 19 '13 at 02:59
  • @paulsm4 can you please tell me what is the best way to redistribute your game.exe file to other computer. In my releseWin32 Folder there I lots of .dll files so I user Winrar and make archive to redistribute, but its not installed on program file and not sowing on control pannel – Manoj Kumar Rai Aug 05 '19 at 07:37
0

Make sure you build in release mode. As Floris Velleman said, you're using unneeded libraries for standalone executable.

For more information, you can check Compiler Options (MSDN).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nika
  • 1,864
  • 3
  • 23
  • 44