Visual C++

Visual C++ is one of the Microsoft C++ compilers.

Warning: This product compiles code which calls shared dlls - specifically msvcrt and mfc42. This means that to distribute your code, you will need to also distribute these dlls. As a result, your code will always be unreliable and simply installing it may cause a full and unrecoverable system failure.

MFC Warning

If a program uses the MFC (Microsoft Foundation Classes), it may have severe problems. In particular, I have seen programs compiled under Visual C++ 5.0 crash when another program compiled under Visual C++ 6.0 was simply loaded on the same machine. (We were running Windows NT 4.0)

These Dr. Watson failures were traced to different versions of MFC42.dll. The program ran fine when Version 4.21.7303 was loaded, and failed (crashed) when Version 6.00.8447 was loaded.

Versions 6.00.8xxx are loaded with Windows 98 Second Edition, Windows 2000, Windows ME, Office 2000, FrontPage 2000, Visual Studio 6.0 SP3, and many other products. In addition, loading any C++ application which uses MFC and is compiled with Visual Studio 6.0 SP3 will install a new dll.

For information on which products install a specific dll version, see the Microsoft DLL Help database. Enter mfc42.dll as the filename.

I don't know if all the 6.0.8xxxx versions cause the problem, or if Microsoft decided to fix it, but this single design failure is enough to make me very leary of ever using MFC.

I mean, how can you design a product that will propably fail the next time someone adds new software to their machine?

Even more to the point, how can you design a product that will propably cause existing/working software on your client's machine to crash simply because your client loaded your software? (You can bet that you will get the blame, not M$.)


I started learning Visual C++ on a machine I inherited - ie one which was already configured. Great software, it only took me 5 days to figure out how to add a button to a form without writing code. (I may be a little slow, but 5 days is still ridiculous.)

As usual, the provided help files were worthless. On the web, I found that page 5 of AppWizard and ClassWizard explained how to display the standard controls - buttons, edit fields, ...

The final solution was simple, simply right click in the toolbar area and enable Controls. Then you simply select the control you want and place it on the form.

Now the only problem is how to add code to a button. (In general, double clicking the button places the cursor at the correct point in the source file. But, on one form I was creating, nothing happened.)

When I started out, there was nothing "visual" about Microsoft's Visual C++ 6.0 product. All there was was a text editor.

If you wanted to design a form (a user interface) then you had to write code. This method of form design has been obsolete for 10 years.

Well, I thought I would get an example. In the Help, I selected Visual C++ Documentation and searched for Hello World - the 5 examples were grayed out! (Well, that's worthless.)

Well, I eventually found instructions indicating that I probably want to run the MFC wizard. Guess what, it is possible to statically link the MFC library and avoid the MFC DLL Hell I've seen so many times.

Boy, it takes a long time for the first compile - but subsequent compiles are instantaneous. The exe file is only 2 Meg. (Unbelievable for just 2 buttons - 15 meg for everything. Mfc42.lib alone is about 2 Meg.)

It is not obvious how to add additional buttons. Perhaps they are instances of CButton. But there are no examples. CButton is defined in afxwin.h (MFC) and derived from CWnd. A text property is defined under CWnd - use GetWindowText & SetWindowText. There does not appear to be a property for the button text.

The buttons appear to be defined in *.rc (resource file). Notice also that *.rc is the name of the displayed form. You would think that there would be a way to add another mfc component to the form. (With Visual Basic, Delphi, or almost any other modern development platform, this task is obvious. Find the button object on some palette and use it to create a button on the form. Simple. It would be hard for "Visual" C++ to make this more obscure.) It turned out that someone had turned off the palette - to see it, right click on the toolbar and enable Controls. Tools / Customize... / Toolbars can also be used to enable the pallet, but View / something would have made a lot more sense than View and it would have taken fewer days to find. (5 days is a lot :(

Using the Integreated Debugger

This is very simple in Delphi, Borland C++, and MS Access, just click in the left margin to set/clear a breakpoint and run your program - execution automatically stops at the breakpoints.

But for Visual C++ 6, Microsoft has a better idea,

If you click on the ! (Execute) icon, the breakpoints are ignored. (Well, that wasn't obvious to me.)

Oh, yes - the built-in help is not half as clear as this. If you follow those instruction, you'll never get it to work. (That's right - they're wrong.)

If the icons are not visible, right click in the toolbar area and be sure that the Build MiniBar is visible. Also be sure to click on the line where you want the break point.

One great feature is that some of the variables in scope are displayed at the bottom of the screen. The variable which just changed is in red. You can also expand the currect class (this) and see all the current settings.

How to Display a Pointer as an Array

If you expand a pointer and you only get a single item, just add ",n" to the entry in the watch window where n is the number of elements to expand. For example, if you have a foo * pFoo pointing to an array of ten elements, put pFoo,10 in your watch window to see all of the element. This can be useful to view parts of a large array. If pFoo points to an array of 5,000 elements, you might use (pFoo + 2000),10 to see elements 2000 through 2009. (From Microsoft Visual C++ Tips and Tricks)

Moving an Existing Project to Visual C++

All right, you have some source files from another development environment and you want to compile them in MS Visual C++. Of course, that is just a start - now you have to fix things that are implemented differently in this compiler verses the one you were using. For instance, with Visual C++ 6, the some standard classes require a namespace command before they will work. Or you could use these instead.

By the way, one of the great things about Visual C++ is the file index on the left hand side of the screen - just double click the file you want and it comes to the top.

References - C/C++
Lots of links (but run in a frame) - MFC Visual C++ Basic Tutorial - Very good except that it continuously says
MFC is compatible across the entire Windows family
which is not exactly true. Newer versions of mfc are known to crash older projects. AppWizard and ClassWizard (page 5 explained how to display the standard controls - buttons, edit fields, ...)

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Languages / VisualC++ / index.html