- Building an MFC Application
- Building a Managed .NET Framework Application
- Comparing the Differences
- Summary
- Q&A
- Workshop
Comparing the Differences
Although the process of building the MFC application was more automated with wizards and form designers, the resulting code of the two applications shows that the MFC application is much more complex. If you take into consideration that the .NET application has no resource file to describe the Windows Form and remove the form definition from the comparison, the .NET application is significantly smaller and even easier to read.
Looking at a few of the major differences between the applications shows a fundamental distinction in the way a .NET application is developed versus how an MFC/Win32 application is developed.
The first main difference is that an MFC Windows application always starts with a CWinApp derivative. The InitInstance() method is overridden and provides the startup initialization for the application. By contrast, the .NET application doesn't require an application class. The .NET application's entry point is the main() function, whereas an MFC/Win32 application's entry point is a WinMain() function encapsulated within the MFC library.
Another major difference you should notice while looking at both applications is that the .NET application does not delete anything it allocates with new. This is because the .NET Framework frees all objects once they are no longer referenced. This is done by the garbage collector automatically. This eliminates the problems of memory leaks in your applications.
Finally, the way that events are handled is quite different between the two applications. With MFC, a message map entry is added to the class's message map, which maps an event or Windows message to a class function. In the .NET Framework, there is no message map; therefore, each object has events associated with it to which you can attach an event handler that is called when the events occur.
For a further comparison of the two applications, look at the code for the applications on the accompanying CD and compare them in more detail. In the end, you should find the .NET application cleaner and easier to work with than the MFC application.