Previous Next
Programmers Guide for .NET Chapter 8 - Programming in C++ .NET

Chapter 8 - Programming in C++ .NET

DB Visual ARCHITECT (DB-VA) can generate C#.NET source code so you can implement your application by C# programming language directly but you can also choose another language (VB.NET or C++) based on your taste in the .NET Framework. DB-VA generates DLL file and persistent libraries that can be referenced by .NET projects of language other than C#.

In this chapter:

Introduction

C++ is an Object-Oriented Programming (OOP) language that is viewed by many as the best language for creating large-scale applications. The .NET Framework contains a virtual machine called Common Intermediate Language (CIL). Simply put, programs are compiled to produce CIL and the CIL is distributed to user to run on a virtual machine. C++, VB.NET, C# compilers are available from Microsoft for creating CIL. In DB-VA you can generate C# persistent source code and DLL file, so you can reference the DLL file and persistent library in Visual Studio .NET 2003 and develop the C++ application.

In the following section, you will develop a C++ application. The application is exactly same as the one in Chapter 4 – Developing Standalone .NET Application sample, but this time you use C++ instead of C# for development. You need to download the Chapter 4 sample application because it contains DLL file and persistent libraries for your C++ project.

Generating DLL File

  1. From the menu bar, select Tools > Object-Relational Mapping (ORM) > Generate Database… to open the Database Code Generate dialog box.

  2. Check the Compile to DLL option to generate the DLL file.

Creating C++ Project

  1. Open Microsoft Visual Studio .NET 2003.
  2. Select File > New > Project … from the menu.

  3. Select Project Types as Visual C++ Projects and Templates as Windows Form Application (.NET) and Location for the new application.

  4. The School System Project is created.

  5. Right click Standalone School System cpp Project, select Add > Add New Item… from the popup menu.

  6. Select Category as Visual C++, Template Windows Form (.NET) and enter the name for the form called “SchoolSystemForm”. This is the start point for the application. 

  7. Append the following content to the SchoolSystemForm.cpp file (Source files/SchoolSystemForm.cpp). This is the main method for C++ Application to execute.

    #include <windows.h>

     

    using namespace StandaloneSchoolSystemcpp;

     

    int APIENTRY _tWinMain(HINSTANCE hInstance,

                                        HINSTANCE hPrevInstance,

                                        LPTSTR lpCmdLine,

                                        int nCmdShow)

    {

        System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;

        Application::Run(new SchoolSystemForm());

        return 0;

    }

  8. Remove the Form1.cpp and Form1.h files.

Adding Referenced Project

  1. Right click References under the Standalone School System C++ project and select Add Reference….  Reference the C# example DDL file and persistent libraries for developing the C++ application.

  2. Click Browse… on the Add Reference dialog box to select the folder of the downloaded C# standalone application sample. Select C# sample folder/bin/SchoolSystem.dll and all libraries in C# sample folder/lib.

Working with the Generating Code and Persistent Library

C# and C++ are both languages that built on the .NET framework and they both accomplish the same thing, just using different language syntax. In this section, you will learn how to work with Generate Code and Persistent Library with C++ language.

Running the Application

To execute the C++ application, select Debug > Start (F5) on the menu bar Visual Studio .NET 2003.


Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com