This blog is about developing Windows applications using Visual Studio. All postings on this weblog are provided "AS IS" with no warranties, and confer no rights. Use of any samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm
Your host Nikola Dudar is a Program Manager in Windows division of Microsoft Corporation. He has been working on Windows Web Services API during Windows 7 and various additions to Visual C++ during VS2005 and VS2008. More details are in LinkedIn profile under Nikola's formal name Mykola Dudar.
If you are interested in program management and project management, check out my other blog at http://www.pmsnack.com/ where I collect best practices and other topics interesting to program and project managers.
To send feedback, comments or requests for new posts, please use the contact form.
Another FAQ from VC++ Express users is: "I give my VC++ application to my friend, and it does not run on her computer." This happens because VC++ Dlls have to be redistributed to another computer together with this application.
There are three ways to get an application built with VC++ Express 2005 to run on another computer that does not have VC++ Express installed:
Ask user of that computer to install Visual C++ Redistributable Package (VCRedist_x86.exe) to install all Visual C++ libraries as shared side-by-side assemblies into the native assembly cache (WinSxS folder). This package can be downloaded from the Microsoft download site Microsoft Visual C++ 2005 Redistributable Package (x86). Redistributing Visual C++ libraries using this package is recommended for applications built with Visual C++ Express.
Build another installer of VC++ libraries using Redistributable Merge Modules installed by VC++ Express into Common Files\Merge Modules. I am describing this approach below in more details.
Statically link your application to VC++ libraries. I recommend against statically linking because static linking prevents your application from running against the most up todate version of VC++ libraries installed on your computer. For example, consider an application that is statically linked to a particular library, running on a client computer with a new version of this library. The application still uses code from the previous version of this library, and does not benefit from library improvements, such as security enhancements.
So if you have decided that you cannot use Microsoft Visual C++ 2005 Redistributable Package (x86) and wisely avoid statically linking to VC++ libraries, you may build a custom MSI that deployes VC++ libraries using four merge modules with CRT library installed by VC++ Express. In my case there are installed in D:\Program Files\Common Files\Merge Modules\:
D:\Program Files\Common Files\Merge Modules\
Clearly I assume that you have read the EULA and redist.txt and do understand that redistribution of debug applications is not allowed. You can simulate redist of debug binaries in your office, but if it goes outside to another computer, it must be application build in Release mode. So please read the EULA and redist.txt carefully and understand what you can and what you cannot redistribute.
I am going to show now how to one can use MSMs to install VC++ DLLs to another computer. I have VC++ Express installed on my computer and I want to make it run on another computer that does not have VC++2005 installed. Here is what I do:
1. I download WIX from sourceforge.net, here is the link http://sourceforge.net/projects/wix . More specific I am going to download from this link, http://prdownloads.sourceforge.net/wix/binaries-2.0.3220.0.zip?download but you may use another build of WiX, perhaps more recent or older then one I use.
2. I am going to unzip this package to D:\WiX\
3.Now I am going to open Visual Studio 2005 Command Prompt (Start>All Programs>Visual C++ 2005 Express Edition>Visual Studio Tools>Visual Studio 2005 Command Prompt)
4. I am typing uuidgen –n2 and click Enter. This generates two UUIDs for me that I am going to use later in Step 6.
5. Now I am going to create two XML files in D:\WiX. First VCCRT.wxi, second VCCRT.wxs.
6. First, I am creating D:\WIX\VCCRT.wxi with the following content :
<?define PRODUCT_ID=!!!! REPLACE WITH UUID1 FROM STEP 4 !!!! ?>
<?define PACKAGE_ID=!!!! REPLACE WITH UUID2 FROM STEP 4 !!!! ?>
Attn: I am going to use two UUIDs generated for me by uuiedgen.exe in the Step 4 to define PRODUCT_ID and PACKAGE_ID. On purpose, I am not listing UUID generated for me, so to help readers of this article avoid using same UUID as someone else.
7. Second, I am creating D:\WIX\VCCRT.wxs with following content
<?include $(sys.SOURCEFILEDIR)\VCCRT.wxi ?>
Name='MSI to redistribute my app'
Language='1033' Version='220.127.116.11' Manufacturer='Me'>
Description='MSI to redistribute my app'
Comments='MSI to redistribute my app'
<Media Id='1' Cabinet='VCCRT.cab' EmbedCab='yes' />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Merge Id='CRT' Language='0' src='D:\Program Files\Common Files\Merge Modules\microsoft_vc80_crt_x86.msm' DiskId='1' />
<Merge Id='CRT Policy' Language='0' src='d:\Program Files\Common Files\Merge Modules\policy_8_0_Microsoft_VC80_CRT_x86.msm' DiskId='1' />
<Feature Id='CRT_WinSXS' Title='CRT WinSXS' Level='1'>
<MergeRef Id='CRT' />
<MergeRef Id='CRT Policy' />
8. Now I am going back to command line, change current directory, compile and link msi
9. That's it, MSI is created. It should be a file D:\WiX\vccrt.msi. If you see errors, take a look on troubleshooting section below.
10. Now I copy my application and vccrt.msi to another computer where I want this application to run which does not have VC++ Express installed. After I have copied my EXE and vccrt.msi, I will first run vccrt.msi before running my EXE.
11. Well my application works just fine. If your application does not start after MSI is installed, please see TroubleShoting section below.
1. Error message CNDL0054 from candle.exe
candle.exe : error CNDL0054 : The document element name 'Include' is invalid. A WiX source file must use 'Wix' as the document element name.
Cause: you have tried executing >candle.exe vccrt.wxi -out vccrt.wixobj instead of >candle.exe vccrt.wxs -out vccrt.wixobj
2. Error message CNDL0009 from candle.exe
D:\WiX\vccrt.wxs(6) : error CNDL0009 : The Product/@Id attribute's value, '!!!! REPLACE WITH UUID FROM STEP 4 !!!! ', is not a legal guid value.
D:\WiX\vccrt.wxs(10) : error CNDL0009 : The Package/@Id attribute's value, '!!!! REPLACE WITH UUID FROM STEP 4 !!!!', is not a legal guid value.
Cause: Edit vccrt.wxi and replace !!!! REPLACE WITH UUID FROM STEP 4 !!!! with UUID generated in Step 4
3. Error Message CNDLXXXX from candle.exe
Cause: No idea, mistake happen when you copy/pasted XML from this post. See WiX documentation for troubleshooting.
4. Error on start of application either a message box that says "This application has failed to start because the application configuration is incorrect" or "The system cannot execute the specified program"
Cause: First, check that your application is built in Release mode. If it was Debug application, you will see OS errors that let you know that either msvcm80d.dll or msvcr80d.dll is not loaded. Second, check if you have deployed all Dependencies of this application. Use depends.exe to see dependencies of an application
5. Error message box while starting your application that says "To run this application you first must install .Net Framework of version v.2.0.xxxx".
Cause: You application contains managed code and depends on presence of .Net Framework. For C++ applications it means that it has been compiled as /clr, /clr:pure or /clr:safe. You have install .Net Framework.
6. After you have installed MSI and you run your application you still get errors described on this page in MSDN , please make sure you have done all steps exactly as they are described and repeat them. Also check out general troubleshooting section in MSDN docs for issues around deployment of Visual C++ libraries.
For any additional help with redistributing applications built with VC++ Express, please check out discussions or ask your question on VC++ Forums, http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=29&SiteID=1.
VC++ Forums, http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=29&SiteID=1.
>> isn't it possible to automate this procedure _completely_ from the VS environment?
Yes, VS has setup project that you can use to build a simple MSI. It may not generate and MSI that meets requirements of enterprise-level deployment. However it allows creating simple MSIs that meet most of requirements. You may find more information in docs, (http://msdn2.microsoft.com/en-us/library/ms227381(VS.80).aspx)
Please make sure you do reasonable amount of testing before using _USE_RTM_VERSION define for reasons I have mentioned in my reply on forums, (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1034641&SiteID=1&PageID=1). If you are not interested in your application taking advantage of security and reliability related changes delivered in SP1 version of VC++ libraries, you may just uninstall SP1 and continue using RTM version of VS.
A reader of the previous post on my blog has posted two questions about using SP1 version of VCRedist.EXE
First: thank you, thank you, thank you.
i've been looking for a workaround to my program not working in other machines despite the redist being installed, and after it was working, it seems because the redist is not compatible with the SP1 of VC++ express.
Your instructions are clear and easy to follow.
1 note: i did not find the uuidgen available at the VS command prompt, and had to use:
C:\Program Files\Microsoft Visual Studio 8\VC>"C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\Uuidgen.exe" -n2
it would be good if you added a note to this blog that the redist is not available yet for sp1 VS express (but wouldn;t it be better if the redist was made available together with the development platform?)
thank you again
>> Yes, VS has setup project that you can use to build a simple MSI. ...
is this also available in VC++ Express ?
Dear Mr. Dudar:
Congratulations for this blog, excellent!
I followed exactly the steps you described to creat the installer, when I move to other PC, the installer works fine, but when I click on my .EXE file, I get that famous message box:"This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."
Rookie Question: how do I make sure that my application is being built in release mode?
Does Microsoft have a place where updated MSM files can be downloaded? On my machine i have one MSM called "Visual C++ 8.0 CRT (x86) WinSXS MSM Beta2", which is version 8.0.50727.42. However, when I build an application, the manifest says it want to use 8.0.50727.762. Is this version available in an MSM file somewhere?
I would like the answer to Christopher Frenning's question too please.
I understood VS2005 SP1 should install version 762 but I have installed this and I still have version 42 although the VCREDIST.EXE I have contains 762. I want to use the merge modules however and cant find the 762 versions anywhere
microsoft_vc80_debugcrt_x86.msm in "C:\Program Files\Common Files\Merge Modules" installs C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c.
But what about _8.0.50727.762_ DebugCRT?
762 version is VS2005 SP1 version of VC++ libraries. VS2005 SP1 update supposed to overwrite RTM version of MSMs on your computer with the SP1 version of MSMs. If after installing VS2005 SP1, you still see RTM version of MSMs on your hard-drive, something went wrong during install. Heath keeps track of all installation issues with VS2005 SP1 and publishes work around on his blog, http://blogs.msdn.com/heaths/. Check out for example list of known issues, http://blogs.msdn.com/heaths/archive/2007/01/11/known-issues-with-visual-studio-2005-service-pack-1.aspx Usually repair of installation helps to update all files installed by VS2005 SP1.
I used to work with the vcredist.86 but it is no longer work and i do not know why?
Nikosa... Thanks for this ... very helpfull. The problem I have is that in release version, I still get "The system cannot execute the specified program." and dependency walker does not show any missing dependency.
Any suggestion ?
I have to say: All three mentioned methods (statically linking, using this 3rd party tool Wix and this distribution package) are very unhandy even it would work, which means no one of the above methods worked for me.
First approach: The Wix method:
I do not have an exe called uuidgen.exe. I searched in all my programm folders and in the windows folder as well. I have installed MS C++ 2005 (Version 8.0.50727.762)
Second approach: Installing Framework and this redistribution package on the second PC. The error is the same as without installing anything: application configuration is incorrect.
My project is a Visual C++ Windows Forms Application. On the PC where the VC++ Express Edition is installed both, the debug and the release exe work. It is a very simple application with a serial port instance to send some data to a controller board. (I didn't intend to give it to anybody but now our customer likes the little prog and wants it without installing VC++)
1>LINK : warning LNK4044: unrecognized option '/MT'; ignored
As I would like to give the "uC bord testing application" to our customer aqnd so I would be very happy for any help to get one of these three approaches working. But, as some have mentioned already before:
What Microsoft does is a NIGHTMARE! This is the worst thing ever. Developers should spend their time in beeing creative and not in "this administrative stuff".
Marco, if you're doing anything with C++ you'll sooner or later want the Windows SDK (previously Platform SDK). It's potentially big download but the options can be set so that it's under 200 MB with basic stuff for usermode development.
And it should have the uuidgen and bunch of other very useful tools you don't find elsewhere such as graphedit.
And the VS C++ IDE should also have uuidgen type of tool integrated, look in the menus! Atleast the full version, not sure about Express.
uuidgen is part of Windows SDK. Now the wix method works and I could run the prog on another pc. Thanks for the hint.
I think these steps could be easily integrated in VS C++ Express and would save a lot of people a lot of time.