Bibliophile

A trivial blog of a bookworm

Monday, March 20, 2006

Running Visual C++ 2005

Well, I have installed a copy of Visual Studio 2005 professional edition on my PC last week. Beware ! There is no .NET postfix in Visual Studio 2005. I made an enquiry for Visual Studio .NET 2005 but a supplier reply me there is no such thing as Visual Studio.NET 2005. Let it be. It does not really matter whether there is postfix .NET in product name or not since it is running on .NET framework 2.0. My concern is how it backward compatible with previous version. I have limited time to write software for my current project.

I created simple MFC Dialog-based application. Hoping that it would work in Visual Studio 2005 with MFC version 8. I still need to write unmanaged code in my new software as I don't want GC(Garbage Collector) to interfere my critical thread. I had added in the following code under OnOK() procedure.

AfxMessageBox("Hello");

When I compiled the program it give me an error. So I tried another attempt by adding the following code.

CString str;
int i = 1;
str.Format("%d",i);
AfxMessageBox(str);


I compiled again. I still got run time error saying that CString format function cannot accept that parameters. I was confused and search inside MSDN. It wrote simple message box can be displayed by

AfxMessageBox("Test");

I tried next time using type casting to remove error message.

AfxMessageBox((LPCTSTR)"Hello");

I can successfully compiled that time. However, it displayed Chinese Characters instead of hello when I run the program. I tried another way to solve the problem again.

CString str;
str = "Hello";
AfxMessageBox(str);


It work!! I totally lost confident that I can develop the application on Visual Studio 2005 with traditional MFC coding style. In the subsequent day, I found out that message box can be displayed by

AfxMessageBox(_T("Hello"));

My first encounter with Visual Studio 2005 is not so sweet.