3

If I write an application using MFC libraries in C++, in deployment stage do I require to install some sort of frameworks or stuff like that? My intent is to have a standalone exe without complicated installation scripts.

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
Claudio Ferraro
  • 4,551
  • 6
  • 43
  • 78
  • All of this is explained under [Redistributing the MFC Library](https://msdn.microsoft.com/en-us/library/ms235264.aspx). Specifically: *"If you statically link your application to MFC (that is, if you specify **Use MFC in a Static Library** on the **General** tab in the **Property Pages** dialog box), you do not have to redistribute Mfc100u.dll or Mfc100.dll."* – IInspectable Jan 08 '16 at 14:40

2 Answers2

3

If you're developping a local application for your own organisation, you could go for static linking, as suggested by Danny.

But static linking is not the method recommended by Microsoft: every time there's an MFC related patch (example here) or z patch for another library, you'll have to recompile your code and redistribute or reinstall it in order to avoid PC's being exposed to security vulnerabilities.

This is why Microsoft recommends to use dynamic libraries: these are easier to update/replace (eventually latest versions are already installed; or automatic windows update; or if necessary manual download of the latest version).

If you go for dynamic approach:

  • there are a couple of mfc*.dll to distribute with your application, together with other standard libraries, such as Msvcr100.dll. It's all explained in the article. Installing such files in your app's directory has the advantage of a leaner installation process. But you have to take responsibility for their update in case of necessity.
  • or you choose to use Microsoft's redistribuable packages. These can be downloded directly from Microsoft's and are contained in a selff-installable file: vc_redist*.exe. Here some explanations on how to use them in installation process. It might install more dlls than required, but vc_redist is an installed Microsoft product that is kept up-to-date with Windows Update.
Christophe
  • 68,716
  • 7
  • 72
  • 138
  • MFC binaries are not part of Windows. They aren't part of the automatic Windows Update either. There is no official statement that implies or explicitly states, that MFC would ship as part of Windows. Besides, you should never rely on certain binaries being there: Always install all required binaries. Into the application's directory. – IInspectable Jan 11 '16 at 01:17
  • @IInspectable I fully agree that you should not rely on the assumptions that the dlls are already there. For Microsoft's recommendation to use dll rather than static link, see the links in my answer. For the fact that MFC is covered by Windows update [when installed with vc_redist](https://msdn.microsoft.com/en-us/library/dd293575.aspx), is clearly demonstrated in [THIS](https://technet.microsoft.com/library/security/ms11-025) security bulletin. Of course, MFC won't patch the DLLs that you install localy in app folder. – Christophe Jan 11 '16 at 06:38
  • The security bulletin talks about a **vulnerability**, and that Microsoft Update will provide a fix for specifically this vulnerability. This does not imply, that *"eventually latest versions are already installed"* on any given client's machine. [Windows is not an MFC delivery channel](https://blogs.msdn.microsoft.com/oldnewthing/20080111-00/?p=23843). – IInspectable Jan 11 '16 at 08:35
  • @IInspectable I think there is a misunderstanding here: I already confirmed your point that one shouldn't rely on assumption that the dds are already there. When I explain that dlls allow easier servicing, I give the example of "*eventually latest versions are there*", because if there is the latest version on on the target PC, vc_redist will skip the unnecessary installation step, which will shorten the install process for the user. But If you see a better approach, don't hesitate to propose another answer: I promise to upvote it if it's good and brings new insights :-). – Christophe Jan 11 '16 at 19:30
  • I see what you are trying to say. Still, though, Microsoft does not recommend using VCRedist_.exe over the other deployment methods for the MFC library. Manually installing the DLLs into the application folder has the advantage, that it doesn't trigger a UAC prompt (as is the case with VCRedist_.exe or using the respective merge module). It's also not affected in case another application's uninstaller erroneously removes any of your dependencies from the system. – IInspectable Jan 11 '16 at 20:01
  • It's a valid point: Microsoft recommends DLL, but doesn't favour one way over the other.to distribute them. The UAC point can be an important aspect, especially for ready to go apps to be installed on usb sticks. – Christophe Jan 11 '16 at 22:01
2

If you link MFC statically, there is no need for external files.

Project Settings / General:

Use of MFC: Use MFC in a Static Library

But, as Christophe mentions, it is not recommended by Microsoft.

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
  • 1
    True, but it's not recommenced by Microsoft: for every security patch affecting mfs, you'd have to rebuild your app and redistribute it to your custmers. Or leave them exposed to vulnerabilities, which is not an acceptable option – Christophe Jan 08 '16 at 12:34