TexBlog

Steve Teixeira's Blog -- Thoughts on parallel computing, Microsoft, the industry, and life

MFC or WinForms: More Advice

MFC or WinForms: More Advice

  • Comments 14

Tom Zagotta brings up several good points in his comment.  There are three ideas in particular that Tom brings up that I want to try to address:

  1. MS should be clear about the future of MFC.
  2. MS should provide better guidance on when to use MFC vs. WinForms.
  3. It would be helpful to developers if they knew more about how MS uses these libraries.

Let me first say that I agree on all three fronts.  We need to communicate this stuff better, and when people tell us we aren't doing it we should listen and then fix it.  Let me also add by way of disclaimer that this is a conversation.  I'm not communicating or setting policy here.  I'm giving you my personal perspective on things.  If we need a more formal means of communicating this stuff later we can do that.

The future of MFC
I'm sure many of you read the
MSDN article I wrote on this topic.  If not, go ahead.  I'll wait for you.

Okay, ready? Good.

It's true that MFC changes in VS 2005 are modest in comparison to changes in the .NET platform, VS IDE, C++/CLI, C#, ASP.NET, etc.  I think this is likely to be the case going forward.  As I intimate in the article, future work done on MFC is likely to be focused on integrating with new platform features, managed and unmanaged.  I think there will be small improvements made to MFC itself, like ongoing bug fixing, like the security features in 2005,  and like some of the improvements mentioned by Victor Volkman.  While we definitely want owners of MFC code bases to have easy access to the latest and greatest platform features (things like Longhorn APIs and Avalon come to mind), the innovation (dare I use that work this week?) is probably going to happen elsewhere in the tool stack.

Okay, so should I use MFC or WinForms?
Good question.  I wish I had an easy answer, but I don't.  So let me throw out some information that will hopefully at least help a few developers with the decision.  If you know whether you need to go managed or native, then the answer is pretty easy today because WinForms is managed and MFC is native.  However, the answer may not always be this easy, as there has been a little research done internally on the feasibility of porting MFC to .NET.  While I'm on the topic, let me throw the question out there:

Q: Would MFC.NET be useful to you? What, specifically, would be the value for you? Or are you happy with the current native/managed framework dividing lines?

If you're undecided on managed vs. native frameworks, then answering the question obviously requires a deeper look.  Generally speaking, I would default to a decision of WinForms unless there was a specific reason why this would not be possible.  Some of these reasons might include necessity of control over performance characteristics, application startup time, working set size issues, .NET Framework runtime deployment concerns, or maybe a need for extensive OLE document support.  Some reasons I would default to WinForms include the superior design time experience, my preference for working in managed code, my personal affinity for the componentized WinForms framework structure, and the availability of resources on the newer frameworks should I need help.  With all of that said, it's also worth noting that while WinForms is a great windowing framework, MFC is more mature as an application framework.

As a final note here, I think the fact that all of this is so difficult to explain is because a hole has developed in our application framework story.  I think the time is coming due for a new MS framework that blends the rich application features of MFC with the more modern design philosophies of WinForms or even Avalon.  I personally think it would be really cool is if such a framework could also accommodate forms written in MFC, WinForms, Avalon or even straight Win32 API and tie them all into one coherent application architecture.  This is just me mentally riffing, though.  I know there are some framework research projects underway, but I'm haven't yet looked into the directions they're heading.  At any rate, such an effort -- if we did end up going for it -- would probably be at least 18-24 or more months out.

So, what does MS use?
Almost all current Microsoft products are written in VC++.  Very few use MFC.  Some newer projects are being done in C# and C++/CLI.

I don't think it was ever a huge secret that MFC never caught on significantly within Microsoft.  The Office apps would seem to have been the biggest candidates, but each is instead written with its own very specialized framework tailor made for the application.  At any rate, that ship has sailed, and we're unlikely to see new Microsoft projects being written from the ground up in MFC.

Regarding managed code, people often ask me, "What does Office use?" After all, the Office apps represent enormous native C++ code bases, so .NET must be really ready for serious application when the Office team buys into it, right?  Hard to argue with that logic.

If the Word team, or any ISV, asked me when they should use .NET I would tell them this: use it were it makes sense for you.  Don't just jump into .NET and hope for the best; understand where you can get the most value from .NET and use C++/CLI to move in those directions.  The .NET framework has a lot of great features that can help you build better, cooler, more reliable software, faster.  However, that doesn't mean it would make sense to take a large, perfectly functional native code base and migrate it all to .NET just to say it's now managed code.  What would be the value in that? Rather, if you own a substantial native C++ application today, introduce managed code where it makes sense...

Want to use a powerful third party WinForms grid control in your application? Add a WinForm.  Want to handle some XML? .NET has some good classes for that.  Need to do some cryptography? .NET has good classes for that too.  Need to build in application security? .NET is strong in this area as well.

In the case of Office, they are introducing a new .NET-based programmability framework, and they're also using .NET for some of their server-side bits.  Again, adding value with .NET where it makes sense and not rewriting working code just for the sake of rewriting.

Parts of your application may remain native code indefinitely, again mixing in managed code where there is value.  For example, MS SQL Server 2005 - about as performance sensitive an application as it gets - plans to keep the core database in native code.  However, they are exposing a programmability interface that opens the door to any .NET language plugging into the server.

One of the cool things about VC++ 2005 is that it's equally comfortable in native or managed and the interoperability is really smooth.  As a VC++ developer, you're free to use the platform or library that solves the problem best for you.

Hopefully all of this helps shed better light on the whole MFC/WinForms/native/managed picture.

  • > Q: Would MFC.NET be useful to you?

    In the spirit of some Win32 APIs, I will answer this Boolean question with an "other". It would be nice if the MC++ implementation of .Net classes would interoperate with MFC, and would interoperate with more of the Win32 API types (structs) than they do at present. In the way that CString variables could usually be plopped down into function calls that took char* arguments (I did say "usually"), and operators like += were defined to do useful stuff, it would be nice if .Net Framework classes had the same degree of interoperation.

    > I don't think it was ever a huge secret that
    > MFC never caught on significantly within
    > Microsoft.

    Sure but for new code in its day it was a boon. Why would programmers of new code want to learn Win32 APIs when they didn't have to? And when they did have to, it worked.

    Now for new code for myself, I'm using WinForms in VS2005 beta, but any work for customers still requires VS6.

    Existing MFC code can still be compiled under VS2005, as you said. Now please see if you can teach the importance of this to your colleagues who did in VB. Why would new programmers want to learn VB6 when VB# is fine for new code, right, no problem there. But existing VB6 code can't be compiled under VB--, and there is no migration tool to convert existing VB6 code to VB-- code. There's a tool that can do the easiest 10% of the work and leave the other 90% to be done by hand, which would take longer than writing a new program from scratch. When a customer has a big investment in VB6 that needs rewriting in a completely different language, do you think they'll choose VB-- or even C# or even VC+++WinForms, or do you think they'll choose a language from a vendor that hasn't screwed them yet. You know the value of continuing to support MFC, please see if you can teach your values to your VB colleagues.
  • Hello steve.
    I have few Questions about MFC 8:

    Will I be able to use the .NET security/XML/Crypto modules in my current written MFC 7.0 (via VS 2003) application?
    Will I be able to integrate it easily and smoothly?

    Regarding the VS 2005 secure code:
    I think the big problem of the MFC is the use of its memory allocation(and free).
    I think Microsoft should add memory annotations (at least for local variables).
    Sometimes code writers forget to ReleaseDC, ReleaseBuffer, DeleteObject, etc., an annotation will be very helpful (meanwhile I'm the one who does this job in my company, code reviewing for others)

    Thanks for your attention,
    Janiv Ratson.


  • You can use the .NET security, XML, and crypto classes from MFC 7 in VS 2003 using the managed C++ synatx for interop. It's cleaner in VS 2005 with C++/CLI syntax, but it does work in 2003.

    Thanks for the suggestion on memory annotations. Good feedback.
  • The MFC will remains there as long as applicaton written in MFC are here, we still found some application running on cobol. For new application development, no one will want to use MFC until and unless we can not do without it,and that scenario is very rare..I have worked on VC6 for quite a long time, writing server side component with COM support with MFC as well as with the help of ATL, but now enjoying the learning of .NET framework.. sooner or later we have to learn the .NET languages
  • ..sooner or later we have to learn the .NET languages

    Or move to some other platform ;)

    Why didn't they just introduce some nice object oriented API a la Trolltech...

    If I wanted slow apps, that eat a lot of resources, I'd use Java...

  • Will avalon replace winform or live side by side with it?
  • MFC has some very useful frameworks mainly the document view architecture. sadly dot net does not have this, and its essential to most large scale applications especially if they are mdi. This is not to say one cannot create the class but now there is no standard out of the box way to do it.
  • You're absolutely right. I wholeheartedly agree that the onus is on us at MS to produce a managed framework that provides the doc/view benefits of MFC.
  • Brian,

    Avalon (aka WPF) is not replacing WinForms... they will live together for a long time to come.

    -steve
  • Steve,

    You said, "You're absolutely right. I wholeheartedly agree that the onus is on us at MS to produce a managed framework that provides the doc/view benefits of MFC."

    I think the opportunity to do this really has passed now. Since it is not included in .NET 2.0, we application writers will probably all come up with our own MVC classes to get the job done. In order for a MS implementation to become the de facto standard, it would have to be available by now, I think.
  • I agree it's late, but I'm not sure I agree that the opportunity has passed. Based on my work with VC++ ISVs, there remains a great deal of MFC out there, and moving to Whatever's Next will happen over the next several years.

    BTW, such a framework wouldn't necessarily have to be a part of the .NET framework -- it could be delivered on a different shedule.
  • I am a VB turned C# developer who is responsible for combining a text retrieval API (Folio) with an audio API (NCT), as well as text/audio synchronization database, to create a multimedia application.
    The problem lies with the text retrieval API, as it is not COM compliant.
    I assume that I must use C++ because the search API must be linked in. As this app will have a complex GUI, what windowing framework should be used?
    From what I have been able to dissect from sample applications showing how to use the search API, the c++ application passes the window handle to an API call, which draws and handles the display of the data on the given form.
    I suppose this approach might work with any framework, but I would like to know what one I should use. I will be making a very large number of native calls, and fast loading times would be a bonus. The mp3 decoder and cd/dvd burning API is written in Delphi.
    Should I use MFC and go native? Or should I use native while interfacing with Folio and managed for the GUI? Or should I write an COM interop layer for Folio?
    Please advise. I know nothing about C++ and native code.
  • Nathanael,

    I tried to answer your question here:

    http://blogs.msdn.com/texblog/archive/2006/01/04/509428.aspx
  • PingBack from http://www.keyongtech.com/737807-newbie-to-net-vc

Page 1 of 1 (14 items)