Creating an Unmanaged C++ Application
The best way to test an unmanaged class is with an unmanaged test harness. You'll need to connect the new application with the class you're testing: Either bring copies of both the header file and the implementation file into the test solution, or add the test harness to the solution in which you are building the class. (If you're building a COM component or DLL, your test harness will typically be a separate solution because you will be testing whether your component is properly registered and available from another application.)
This chapter shows you how to make an unmanaged console application that you can use to write C++ programs without needing to know anything about Windows, the Web, or the .NET Framework. Later, when you've written a class, a class library, or a component, you can put your ability to write console application to good use by writing a test harness for your reusable code.
To build a console application that will run on a computer without the .NET Framework installed, follow these steps:
The wizard generates the skeleton of an unmanaged C++ application. After the #include statement that was generated, add these lines:
#include <iostream> using namespace std;
Before the return statement that was generated, add this line:
cout << "Hello from the console" << endl;
Build the project by choosing Build, Build Solution. Run it by choosing Debug, Start without Debugging. You should see output like Figure 2.2.
Figure 2.2. The console application runs in a command prompt and writes characters to the screen.
Now that you know how to create, compile, and run a simple console application in unmanaged C++, you can do a tremendous amount of programming. You can define classes, and then write code to create instances of the class and call their methods . You can write and test hundreds of thousands of lines of code in this way, just by adding lines to the main function (defined as _tmain in Visual C++) that is generated for you when you create a Win32 console project.
These applications don't require the .NET Framework and can't use the functionality of the .NET Base Class Libraries. They can use libraries, such as MFC and ATL, that don't require the framework. They can also use the implementation of the Standard Template Library (STL) that comes with Visual C++. In addition there are hundreds of third-party libraries, most of them free, that manipulate images or equations or molecular simulations while drawing on the power of C++. Your unmanaged C++ code can leverage these libraries to reduce your coding effort dramatically.