Creating an Unmanaged C Application

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:

  1. Open Visual Studio .NET 2003.

  2. On the Start Page, click New Project. If the Start Page isn't visible, choose File, New, Project.

  3. Select the Visual C++ Projects folder on the left and Win32 Console Project on the right.

  4. Enter FirstConsole as the project name (the dialog box should resemble Figure 2.1) and click OK.

    Figure 2.1. Creating a Win32 Console Project called FirstConsole.


  5. Click Finish from the wizard that appears.

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.

Microsoft Visual C++. NET 2003 Kick Start
Microsoft Visual C++ .NET 2003 Kick Start
ISBN: 0672326000
EAN: 2147483647
Year: 2002
Pages: 141
Authors: Kate Gregory

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: