31

I've never been a big fan of MFC, but that's not really the point. I read that Microsoft is due to release a new version of MFC in 2010 and it really struck me as odd - I thought MFC was dead (no ill intention, I really did).

Is is MFC used for new developments? If so, whats the benefit? I couldn't imagine it having any benefit over something such as C# (or even just c++ using Win32 APIs for that matter).

itowlson
  • 73,686
  • 17
  • 161
  • 157
NTDLS
  • 4,757
  • 4
  • 44
  • 70
  • 3
    The question I created before was based on subjective dislike of MFC, this question is inquiring as to MFC's relevance in the present. I was unaware I could edit the other question (after it was closed) which was much less thought out. I am also in the process of deleting that question. – NTDLS Feb 16 '10 at 05:30
  • 1
    10 years later the answer is still YES.... Inertia is strong (when youy have an investment totaling in the hundreds of millions of lines of code...) – David V. Corbin Jan 17 '21 at 15:06
  • 1
    @DavidV.Corbin what's funny is I still look back at this question from time to time. This is awesome! – NTDLS Jan 20 '21 at 14:46

8 Answers8

26

There is a ton of code out there using MFC. I see these questions all the time is this still used is that still used the answer is yes. I work in a very large organization which still employs hundreds of people who write in cobol. If it has ever been used in the enterprise it will continue to be used until there is no more hardware to support it, then some company will pay someone to write an emulator so that the old code will still work.

The navy still uses ships with computers with magnetic cores for memory and I'm sure they have people to work on them. Technology once created can never not be supported. its a bit of the case of Deus ex machina where large organizations aren't completely sure what their system do and have such an overriding sense of fear of brining the enterprise to its knees they have no desire to try out you new fangled technologies(BTW we pay IBM for best effort support on OS2).

Also mfc is a perfectly acceptable solution for windows development given it is an object model which wraps the System API which is pretty much all that most people get out of .net.


As an addendum and since this question is up for a bounty this is a quote from MS regarding mfc in VS 11

In every release we need to balance our investment across the various areas of the product. However, we still believe that MFC is the most fully-featured library for building native desktop applications. We are fully committed to supporting and maintaining MFC at a high level of quality. Here’s a short list of some of the issues that we fixed in MFC for Visual Studio 11:

Here is the link if you want to read the full post

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
rerun
  • 25,014
  • 6
  • 48
  • 78
  • magnetic core memory is less affected by radiation than semiconductor memory, so I would expect that it is still being used in niche applications. – Robert Baron May 14 '21 at 11:53
21

Coolness does not factor in choosing the technology for a new system. Yes if you are a student or want to play around you choose whatever you want.

But in the real world each technology has advantages and drawbacks. A year ago one of the teams started a new project, it was decided that it will be done in MFC. The reason is very simple: they have to use windows api a lot for low level operations with the printer, internet explorer and god knows what else.

C# was not even in the game, the decision was made between MFC and QT, both had the needed functionality, both could easily integrate the low level functionality, the only difference was that some team members already had MFC experience, so they didn't have to waste time and money with trainings.

Let's suppose they choose C# and WPF:
-1 You have to wrap all native C++ and ASM code in a DLL (ouch this can be painful, instead of coding you write wrappers).
-1 You probably need two teams now, one for the ui one for the winapi stuff. It is very unlikely that you'll find a lot of people able to write both C# and winapi stuff. Agreed that either way you need someone to make the interface pretty (programmers usually suck at this and they cost more) but at least with C++ only code, there is no more wait time between two teams, need a ui modification, no problem I don't have to wait for the ui designer, he will make it pretty later.
+1 You can write the UI code in C# and WPF, let's say the UI development is faster, but the UI is only 1/4 of the project, so the total gain is probably very small.
-1 Performance degradation: for every small operation you can't do in C# you call a external DLL (this is a minor issue since the program runs on 8GB RAM Quad Cores).

So in conclusion: MFC is still used for new development because the requirements and the costs decide the technology for a project and it just so happens that MFC is the best in some cases.

  • 3
    Hmmm...Very good explanation! I want to start learning C++ GUI development. Should I learn MFC or QT? What do you say? I offered the bounty. Please give me a good suggestion to get an acceptance. Can I use MFC/QT both for Dx/OpenGL game development and Data-driven applications? – user366312 May 05 '12 at 19:11
  • 2
    In general I find Qt is used more that MFC since it's cross platform and free. In one project we used it on a embedded device running a custom Linux distro. I have never use Dx/OpenGl with MFC or QT, but since Dx/OpenGL only require a window from your program, I see no reason for it not to work with both MFC and QT. –  May 05 '12 at 22:27
  • 1
    Dx/OpenGl is something I did in college and for fun, so I don't have any 'real' experience with it, but I remember that there were some frameworks like "irrlicht" that offered a lot of functionality, including dialogs, windows for GUI. So I guess it makes more sense to use such a framework if you want do develop Dx/OpenGL. –  May 05 '12 at 22:40
  • The notion of Qt being free is a bit tricky, take a look at [this thread](https://www.quora.com/Can-I-use-the-free-QT-for-c++-commercially), looks like a lot of legal nuance there. – For Comment Feb 23 '20 at 17:24
  • Free doesn't automatically mean mean business friendly. The last time I went through the Qt licence, it's pretty restrictive. – Najeeb May 11 '22 at 20:17
15

MFC is still used for some new development, and a lot of maintenance development (including inside of Microsoft).

While it can be minutely slower than using the Win32 API directly, the performance loss really is tiny -- rarely as much as a whole percent. Using .NET, the performance loss is considerably greater (in my testing, rarely less than 10%, with 20-30% being typical, and higher still for heavy computation. Just for example, I have a program that does Eigenvector/Eigenvalue computation on fairly large arrays. My original version using C++ and MFC runs one test case in just under a minute on our standard test machine. Some of my coworkers decided it would be cool to re-implement it in C#. Their version takes almost three minutes on the same machine (quad core, 16-gigs of RAM, so no, not "legacy" hardware). I'll admit I haven't looked at their code too closely, so maybe it could be improved, but they're decent coders so a 3:1 improvement strikes me as unlikely.

With MFC, it's also easy to bypass the framework and use the Win32 API directly when/if you want to. With .NET, you can use P/Invoke for that, but it's quite painful by comparison.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • 3
    How much of that is due to the GUI though? Presumably you're using something like Intel MKL for the math in both cases, so what's actually causing the difference? – Pete Kirkham Feb 19 '10 at 11:11
  • 2
    @Pete:No, this particular program uses no outside code in any of the critical paths. If you'll pardon my sounding a tad conceited, Intel's programmers are good at optimizing -- but I'm better. More seriously, a lot of Intel's optimizations (by chance or otherwise) do quite poorly on AMD processors, which was unacceptable for this code. – Jerry Coffin Feb 19 '10 at 14:04
  • So, would you go for MFC in a new Windows project today? I am interested in your opinion on that. – Aykhan Hagverdili Dec 11 '20 at 15:41
  • 1
    @AyxanHaqverdili: I probably would for a small, one-off sort of thing. For any sort of large, serious project that was going to involve multiple developers and be maintained for a long time? No, probably not. I suppose I could conceive of circumstances that could justify it (e.g., the project fits well with MFC, I already have an entire team who know MFC well, and don't know any equivalent, and I have an extremely tight deadline) but at least as I see things, it's a decision that would need a lot of justification. – Jerry Coffin Dec 11 '20 at 17:11
8

MFC has been updated with every release of Visual Studio. It just isn't the headline feature item.

As for new development, yes. It is still used and will continue to be so (even though I, like you, prefer not to). Many organizations made the technology decision years ago and have no reason to change.

I do think you are talking about well-established shops though, folks with more interest in maintaining / enhancing what has been written rather than stay on the cutting edge.

Shaun
  • 3,928
  • 22
  • 21
8

The release of the MFC Feature Pack (one or two years ago, iirc) was the biggest extension of MFC since around 10 years and it gave quite a new boost to MFC development. I guess a lot of companies decided to maintain their legacy applications, push them forward and delevelop new applications on its basis.

For me (as someone who has to maintain a large MFC application) the bigger problem is the decreasing development and support of (Microsoft and third-party) components rather than MFC itself. For instance is porting to 64bit not easy if a lot of old and unsupported pure 32bit Active-X components are assembled in the application.

Slauma
  • 175,098
  • 59
  • 401
  • 420
3

I did a project last year based on MFC. I'm not sure why MFC was chosen, but it was adequate for making a virtual 3D graphic user interface—a building management security system—with 10 frame per second refresh rate run efficiently on win32-based PCs dating back to the mid-1990s. The executable (which requires only core win32 system DLLs) is less than 400K—not an easy accomplishment with modern tools.

wallyk
  • 56,922
  • 16
  • 83
  • 148
  • 2
    So, development for "legacy" systems? (I'm not being critical, I like legacy systems). My problem is that the MFC DLL's were HUGE (for their time) and quite in inefficient. So if speed or size are a concern why not just stick with the Win32APIs? – NTDLS Feb 16 '10 at 02:05
  • 2
    Because win32 is a huge setback in development time and you'll end up writing wrappers to make it more OO anyway. MFC's dlls aren't that huge, and if it's really an issues you can still link statically. – Roel Feb 16 '10 at 12:52
  • 1
    @NTDLS: So MFC dll's are huge? I guess you think .net framework is smaller, think again. Also I am curious how can you statically link C# code (so that it runs without all the .net dlls) –  May 05 '12 at 17:41
  • 2
    @Ha11owed - No way man! I'm a big ol' fan of .net but that framework is a mammoth! C# is the way tI try to go with any new projects - but I have major love for C/C++ on Win32... but I greatly prefer to do it without MFC. If I'm going got efficiency in the lowest level language I understand then I go as native as I can. – NTDLS Jun 27 '12 at 23:54
  • 1
    @Ha11owed Now .NET Core does it. BTW, it's not meant for GUI development... – Matías Fidemraizer Mar 04 '17 at 12:48
2

There are advantages to staying away from managed code (maybe you're writing a driver UI, or doing COM).

That and there's tons of MFC code out there. Maybe you work for Company X, and need to use one of the zillion DLLs they've been writing over the last dozen years.

Seth
  • 45,033
  • 10
  • 85
  • 120
  • 1
    Agreed! I'm an old-school fan of unmanaged code - but I'm not sure if you can write drivers using MFC (I'm not not saying one can't, I just don't beleive one can. Certainly not a kernel-mode driver). – NTDLS Feb 16 '10 at 02:13
  • 1
    I meant driver UI's (like a "Printer Dialog" or something). Coding up dialog boxes in MFC is *really* fast. – Seth Feb 16 '10 at 02:33
  • 1
    I'm much more accustom to creating C++ Win32 application using a basic resource editor and a WinProc callback - which for me is much faster. Subjective, yes, but I personally see little appeal in using MFC for such applications. This doesnt make me right by any means. – NTDLS Feb 16 '10 at 05:27
  • 2
    Of course writing something without MFC is slower *if one doesn't know MFC*. Writing the same application with MFC is much faster than writing the equivalent in win32, given a competent programmer. – Roel Feb 16 '10 at 12:53
1

I can think of one commercial software title that benefits from using MFC over C#: Wwise[1]. C++ is an obvious choice for the sound engine, so it makes sense to write the authoring tool in C++ as well. It's both an authoring tool and a sound engine. They could have built the authoring tool in C#, and the sound engine in C++, but if they're debugging a problem with the sound engine that's reproducible through the wwise authoring tool, it's easier for them to see the whole call stack just like that.

I think there's some ways of doing a mixed call stack nowadays, but maybe that wasn't there when they first made Wwise? In any case, using MFC ensured that they wouldn't need a solution to the problem of mixed call stacks. The call stack just works.

[1]Wwise is built on MFC: https://www.audiokinetic.com/fr/library/edge/?source=SDK&id=plugin_frontend_windows.html

NickLokarno
  • 300
  • 6
  • 20