Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

VC++
VC++ Introduction
VC++ What's New
VC++ Supported Platforms
Visual C++ Settings
VC++ Breaking Changes
Visual C++ Walkthroughs
Visual C++ Editions
VC++ Project Templates
Visual C++ Guided Tour
VC++ Creating Command-Line Applications
VC++ Windows Applications
VC++ Reusable Code
VC++ Porting
VC++ Unix Users
VC++ Upgrade Wizard
VC++ Migration Primer
VC++ Managed Types
VC++ Member Declarations
VC++ Conversion Operators
VC++ Interface Member
VC++ Value Types
VC++ Boxed Value
VC++ General Language
VC++ Common Programming
VC++ Database Support
VC++ MFC Database Classes
VC++ Record
VC++ Record View
VC++ OLE DB Programming

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Creating Reusable Code (C++)


Previoushome Next






Creating Reusable Code (C++)
A D V E R T I S E M E N T
Now that we have learned how to use the Visual Studio IDE and how to create command-line and Windows applications, we will learn how to write code so that it can be used by multiple applications. One way to do this is to create a library that contains related classes and algorithms. For example, Visual C++ is included with many libraries that any C or C++ application can use, such as the C Run-Time Library and the Standard C++ Library. Without these libraries, there would be no standard way for a C or C++ application to write to the console or determine the current date and time.

Every C or C++ application will likely use one of the previously mentioned libraries. You can also create your own libraries of classes and algorithms that any application can use. With Visual C++, you can create three kinds of libraries:

  • Dynamic link libraries (DLLs).
  • Static libraries.
  • Managed assemblies.

In general, if you are creating a library that can be used by native C++ code, you will create either a dynamic link library or a static library. For more information about how to determine which type of library to create, see DLLs. If you are creating a library that can be used by C++/CLI or any other .NET language such as C# or Visual Basic, you will create a managed assembly.

In this section, we will create a simple library of standard math operations such as addition and multiplication, and we will show how applications can use this library.




Prerequisites

These topics assume that you understand the fundamentals of the C++ language.




In This Section
  • Creating and Using a Dynamic Link Library (C++)
  • Creating and Using a Static Library (C++)
  • Creating and Using a Managed Assembly (C++)
Creating and Using a Dynamic Link Library (C++)
The first type of library we will create is a dynamic link library (DLL). Using DLLs is a great way to reuse code. Rather than re-implementing the same routines in every program that you create, you write them one time and reference them from applications that need the functionality.

This walkthrough covers the following:

  • Creating a new dynamic link library (DLL) project.
  • Adding a class to the dynamic link library.
  • Creating an application that references the dynamic link library.
  • Using the functionality from the class library in the console application.
  • Running the application.



Prerequisites

This topic assumes that you understand the fundamentals of the C++ language.

To create a new dynamic link library (DLL) project

  1. From the File menu, select New and then Project….
  2. On the Project types pane, under Visual C++, select Win32.
  3. On the Templates pane, select Win32 Console Application.
  4. Choose a name for the project, such as MathFuncsDll, and type it in the Name field. Choose a name for the solution, such as DynamicLibrary, and type it in the Solution Name field.
  5. Click OK to start the Win32 application wizard. On the Overview page of the Win32 Application Wizard dialog box, click Next.
  6. On the Application Settings page of the Win32 Application Wizard, under Application type, select DLL if it is available or Console application if DLL is not available. Some versions of Visual Studio do not support creating a DLL project by using wizards. You can change this later to make your project compile into a DLL.
  7. On the Application Settings page of the Win32 Application Wizard, under Additional options, select Empty project.
  8. Click Finish to create the project.

To add a class to the dynamic link library

  1. To create a header file for a new class, from the Project menu, select Add New Item…. The Add New Item dialog box will be displayed. On the Categories pane, under Visual C++, select Code. On the Templates pane, select Header File (.h). Choose a name for the header file, such as MathFuncsDll.h, and click Add. A blank file will be displayed.
  2. Add a simple class named MyMathFuncs to do common mathematical operations, such as addition, subtraction, multiplication, and division. The code should resemble the following:
    Copy Code
    // MathFuncsDll.h
    
    namespace MathFuncs
    {
        class MyMathFuncs
        {
        public:
            // Returns a + b
            static __declspec(dllexport) double Add(double a, double b);
    
            // Returns a - b
            static __declspec(dllexport) double Subtract(double a, double b);
    
            // Returns a * b
            static __declspec(dllexport) double Multiply(double a, double b);
    
            // Returns a / b
            // Throws DivideByZeroException if b is 0
            static __declspec(dllexport) double Divide(double a, double b);
        };
    }
  3. Note the __declspec(dllexport) modifier in the method declarations in this code. These modifiers enable the method to be exported by the DLL so that it can be used by other applications. For more information, see dllexport, dllimport.
  4. To create a source file for a new class, from the Project menu, select Add New Item…. The Add New Item dialog box will be displayed. On the Categories pane, under Visual C++, select Code. On the Templates pane, select C++ File (.cpp). Choose a name for the source file, such as MathFuncsDll.cpp, and click Add. A blank file will be displayed.
  5. Implement the functionality for MyMathFuncs in the source file. The code should resemble the following:
    Copy Code
    // MathFuncsDll.cpp
    // compile with: /EHsc /LD
    
    #include "MathFuncsDll.h"
    
    #include 
    
    using namespace std;
    
    namespace MathFuncs
    {
        double MyMathFuncs::Add(double a, double b)
        {
            return a + b;
        }
    
        double MyMathFuncs::Subtract(double a, double b)
        {
            return a - b;
        }
    
        double MyMathFuncs::Multiply(double a, double b)
        {
            return a * b;
        }
    
        double MyMathFuncs::Divide(double a, double b)
        {
            if (b == 0)
            {
                throw new invalid_argument("b cannot be zero!");
            }
    
            return a / b;
        }
    }
  6. To build the project into a DLL, from the Project menu, select MathFuncsDll Properties…. On the left pane, under Configuration Properties, select General. On the right pane, change the Configuration Type to Dynamic Library (.dll). Click OK to save the changes.
    Note:
    If you are building a project from the command line, use the /LD compiler option to specify that the output file should be a DLL. For more information, see /MD, /MT, /LD (Use Run-Time Library).
  7. Compile the dynamic link library by selecting Build Solution from the Build menu. This creates a DLL that can be used by other programs. For more information about DLLs, see DLLs.

To create an application that references the dynamic link library

  1. To create an application that will reference and use the dynamic link library that you just created, from the File menu, select New and then Project….
  2. On the Project types pane, under Visual C++, select Win32.
  3. On the Templates pane, select Win32 Console Application.
  4. Choose a name for the project, such as MyExecRefsDll, and type it in the Name field. Next to Solution, select Add to Solution from the drop down list. This will add the new project to the same solution as the dynamic link library.
  5. Click OK to start the Win32 Application Wizard. On the Overview page of the Win32 Application Wizard dialog box, click Next.
  6. On the Application Settings page of the Win32 Application Wizard, under Application type, select Console application.
  7. On the Application Settings page of the Win32 Application Wizard, under Additional options, clear the Precompiled header check box.
  8. Press Finish to create the project.

To use the functionality from the class library in the console application

  1. After you create a new console application, an empty program is created for you. The name for the source file is the same as the name that you chose for the project earlier. In this example, it is named MyExecRefsDll.cpp.
  2. To use the math routines that were created in the dynamic link library, you must reference the library. To do this, select References… from the Project menu. On the Property Pages dialog box, expand the Common Properties node, select References, and then select the Add New Reference… button. For more information about the References… dialog box, see Framework and References, Common Properties, Property Pages Dialog Box.
  3. The Add Reference dialog box is displayed. This dialog lists all the libraries that you can reference. The Project tab lists all the projects in the current solution and any libraries they contain. On the Projects tab, select MathFuncsDll. Then click OK. For more information about the Add Reference dialog box, see Add Reference Dialog Box.
  4. To reference the header files of the dynamic link library, you must modify the include directories path. To do this, on the Property Pages dialog box, expand the Configuration Properties node, expand the C/C++ node, and then select General. Next to Additional Include Directories, type the path of the location of the MathFuncsDll.h header file.
  5. The executable does not load dynamic link libraries until runtime. You must tell the system where to locate MathFuncsDll.dll. You do so by using the PATH environment variable. To do this, on the Property Pages dialog box, expand the Configuration Properties node and select Debugging. Next to Environment, type the following: PATH=<path of MathFuncsDll.dll file>, where <path of MathFuncsDll.dll file> is replaced with the actual location of MathFuncsDll.dll. Click OK to save all the changes.
    Note:
    If you want to run the executable from the command line instead of from Visual Studio, you must manually update the PATH environment variable from the command prompt as follows: set PATH=%PATH%;<path of MathFuncsDll.dll file>, where MathFuncsDll.dll file> is replaced with the actual location of MathFuncsDll.dll.
  6. You can now use the MyMathFuncs class in this application. Replace the contents of MyExecRefsDll.cpp with the following code:
    Copy Code
    // MyExecRefsDll.cpp
    // compile with: /EHsc /link MathFuncsDll.lib
    
    #include 
    
    #include "MathFuncsDll.h"
    
    using namespace std;
    
    int main()
    {
        double a = 7.4;
        int b = 99;
    
        cout << "a + b = " <<
            MathFuncs::MyMathFuncs::Add(a, b) << endl;
        cout << "a - b = " <<
            MathFuncs::MyMathFuncs::Subtract(a, b) << endl;
        cout << "a * b = " <<
            MathFuncs::MyMathFuncs::Multiply(a, b) << endl;
        cout << "a / b = " <<
            MathFuncs::MyMathFuncs::Divide(a, b) << endl;
    
        return 0;
    }
  7. Build the executable by selecting Build Solution from the Build menu.

To run the application

  1. Make sure MyExecRefsDll is selected as the default project. In the Solution Explorer, select MyExecRefsDll, and then select Set As StartUp Project from the Project menu.
  2. To run the project, select Start Without Debugging from the Debug menu. The output should resemble this:
    Copy Code
    a + b = 106.4
    a - b = -91.6
    a * b = 732.6
    a / b = 0.0747475
     
    Creating and Using a Static Library (C++)
    The next type of library we will create is a static library (LIB). Using static libraries is a great way to reuse code. Rather than re-implementing the same routines in every program that you create, you write them one time and reference them from applications that need the functionality.

    This walkthrough covers the following:

    • Creating a new static library project.
    • Adding a class to the static library.
    • Creating an application that references the static library.
    • Using the functionality from the static library in the console application.
    • Running the application.



    Prerequisites

    This topic assumes that you understand the fundamentals of the C++ language.

    To create a new static library project

    1. From the File menu, select New and then Project….
    2. On the Project types pane, under Visual C++, select Win32.
    3. On the Templates pane, select Win32 Console Application.
    4. Choose a name for the project, such as MathFuncsLib, and enter it in the Name field. Choose a name for the solution, such as StaticLibrary, and enter it in the Solution Name field.
    5. Press OK to start the Win32 application wizard. On the Overview page of the Win32 Application Wizard dialog box, press Next.
    6. On the Application Settings page of the Win32 Application Wizard, under Application type, select Static library.
    7. On the Application Settings page of the Win32 Application Wizard, under Additional options, clear the Precompiled header check box.
    8. Press Finish to create the project.

    To add a class to the static library

    1. To create a header file for a new class, from the Project menu, select Add New Item…. The Add New Item dialog box will be displayed. From the Categories pane, under Visual C++, select Code. From the Templates pane, select Header File (.h). Choose a name for the header file, such as MathFuncsLib.h, and press Add. A blank file will be displayed.
    2. Add a simple class named MyMathFuncs to do common mathematical operations, such as addition, subtraction, multiplication, and division. The code should resemble the following:
      Copy Code
      // MathFuncsLib.h
      
      namespace MathFuncs
      {
          class MyMathFuncs
          {
          public:
              // Returns a + b
              static double Add(double a, double b);
      
              // Returns a - b
              static double Subtract(double a, double b);
      
              // Returns a * b
              static double Multiply(double a, double b);
      
              // Returns a / b
              // Throws DivideByZeroException if b is 0
              static double Divide(double a, double b);
          };
      }
    3. To create a source file for a new class, from the Project menu, select Add New Item…. The Add New Item dialog box will be displayed. From the Categories pane, under Visual C++, select Code. From the Templates pane, select C++ File (.cpp). Choose a name for the source file, such as MathFuncsLib.cpp, and press Add. A blank file will be displayed.
    4. Implement the functionality for MyMathFuncs in the source file. The code should resemble the following:
      Copy Code
      // MathFuncsLib.cpp
      // compile with: /c /EHsc
      // post-build command: lib MathFuncsLib.obj
      
      #include "MathFuncsLib.h"
      
      #include 
      
      using namespace std;
      
      namespace MathFuncs
      {
          double MyMathFuncs::Add(double a, double b)
          {
              return a + b;
          }
      
          double MyMathFuncs::Subtract(double a, double b)
          {
              return a - b;
          }
      
          double MyMathFuncs::Multiply(double a, double b)
          {
              return a * b;
          }
      
          double MyMathFuncs::Divide(double a, double b)
          {
              if (b == 0)
              {
                  throw new invalid_argument("b cannot be zero!");
              }
      
              return a / b;
          }
      }
    5. To build the project into a static library, from the Project menu, select MathFuncsLib Properties…. On the left pane, under Configuration Properties, select General. On the right pane, change the Configuration Type to Static Library (.lib). Press OK to save the changes.
      Note:
      When you build from the command line, you must build the program in two steps. First, compile the code by using Cl.exe with the /c compiler option (cl /c /EHsc MathFuncsLib.cpp). This will create an object file that is named MathFuncsLib.obj. For more information, see /c (Compile Without Linking). Second, link the code by using the Library Manager Lib.exe (lib MathFuncsLib.obj). This will create the static library MathFuncsLib.lib. For more information about the Library Manager, see LIB Reference.
    6. Compile the static library by selecting Build Solution from the Build menu. This creates a static library that can be used by other programs.

    To create an application that references the static library

    1. To create an application that will reference and use the static library that was just created, from the File menu, select New and then Project….
    2. On the Project types pane, under Visual C++, select Win32.
    3. On the Templates pane, select Win32 Console Application.
    4. Choose a name for the project, such as MyExecRefsLib, and type it in the Name field. Next to Solution, select Add to Solution from the drop down list. This will add the new project to the same solution as the static library.
    5. Press OK to start the Win32 Application Wizard. On the Overview page of the Win32 Application Wizard dialog box, press Next.
    6. on the Application Settings page of the Win32 Application Wizard, under Application type, select Console application.
    7. On the Application Settings page of the Win32 Application Wizard, under Additional options, clear Precompiled header.
    8. Press Finish to create the project.

    To use the functionality from the static library in the console application

    1. After you create a new console application, the wizard creates an empty program for you. The name for the source file will be the same as the name that you chose for the project earlier. In this example, it is named MyExecRefsLib.cpp.
    2. To use the math routines that you created in the static library, you must reference it. To do this, select References… from the Project menu. From the Property Pages dialog box, expand the Common Properties node and select References. Then select the Add New Reference… button. For more information about the References… dialog box, see Framework and References, Common Properties, Property Pages Dialog Box.
    3. The Add Reference dialog box is displayed. This dialog box lists all the libraries that you can reference. The Project tab lists all the projects in the current solution and any libraries they contain. On the Projects tab, select MathFuncsLib. Then select OK. For more information about the Add Reference dialog box, see Add Reference Dialog Box.
    4. To reference the header files of the static library, you must modify the include directories path. To do this, in the Property Pages dialog box, expand the Configuration Properties node, expand the C/C++ node, and then select General. Next to Additional Include Directories, type the path of the location of the MathFuncsLib.h header file.
    5. You can now use the MyMathFuncs class in this application. Replace the contents of MyExecRefsLib.cpp with the following code:
      Copy Code
      // MyExecRefsLib.cpp
      // compile with: /EHsc /link MathFuncsLib.lib
      
      #include 
      
      #include "MathFuncsLib.h"
      
      using namespace std;
      
      int main()
      {
          double a = 7.4;
          int b = 99;
      
          cout << "a + b = " <<
              MathFuncs::MyMathFuncs::Add(a, b) << endl;
          cout << "a - b = " <<
              MathFuncs::MyMathFuncs::Subtract(a, b) << endl;
          cout << "a * b = " <<
              MathFuncs::MyMathFuncs::Multiply(a, b) << endl;
          cout << "a / b = " <<
              MathFuncs::MyMathFuncs::Divide(a, b) << endl;
      
          return 0;
      }
    6. Build the executable by selecting Build Solution from the Build menu.

    To run the application

    1. Make sure MyExecRefsLib is selected as the default project. In the Solution Explorer, select MyExecRefsLib, and then select Set As StartUp Project from the Project menu.
    2. To run the project, select Start Without Debugging from the Debug menu. The output should resemble this:
      Copy Code
      a + b = 106.4
      a - b = -91.6
      a * b = 732.6
      a / b = 0.0747475
    Creating and Using a Managed Assembly (C++)
    The next type of library that we will create is a managed assembly. Using managed assemblies is a great way to reuse code. Rather than re-implementing the same routines in every program that you create, you write them once and reference them from applications that need the functionality.

    This walkthrough covers the following:

    • Creating a new class library project.
    • Adding a class to the class library.
    • Creating an application that references the class library.
    • Using the functionality from the class library in the console application.
    • Running the application.



    Prerequisites

    This topic assumes that you understand the fundamentals of the C++ language.

    To create a new class library project

    1. From the File menu, select New and then select Project….
    2. On the Project types pane, under Visual C++, select CLR. This creates a project that targets the common language runtime.
    3. On the Templates pane, select Class Library.
    4. Choose a name for the project, such as MathFuncsAssembly, and type it in the Name field. Choose a name for the solution, such as ManagedAssemblies, and type it in the Solution Name field.
    5. Press OK to create the project.
    6. By default, when new projects are created, they are set up to use precompiled headers. To disable precompiled header, select Properties from the Project menu. Expand the Configuration Properties node, expand the C/C++ node, and then select Precompiled Headers. From the dropdown list next to Create/Use Precompiled Header, select Not Using Precompiled Header. Press OK to save these changes. For more information on precompiled headers, see Creating Precompiled Header Files.

    To add a class to the class library

    1. After you create a new CLR Class Library, the wizard generates a simple class for you. The names for the header file and source file will be the same as the name you chose for the project earlier. In this example, they are named MathFuncsAssembly.h and MathFuncsAssembly.cpp.
    2. Replace the existing code in MathFuncsAssembly.h with a simple class that is named MyMathFuncsAssembly to do common mathematical operations, such as addition, subtraction, multiplication, and division. The code should resemble the following:
      Copy Code
      // MathFuncsAssembly.h
      
      using namespace System;
      
      namespace MathFuncs
      {
          public ref class MyMathFuncs
          {
          public:
              // Returns a + b
              static double Add(double a, double b);
      
              // Returns a - b
              static double Subtract(double a, double b);
      
              // Returns a * b
              static double Multiply(double a, double b);
      
              // Returns a / b
              // Throws DivideByZeroException if b is 0
              static double Divide(double a, double b);
          };
      }
    3. Implement the functionality for MyMathFuncs in the source file. The code should resemble the following:
      Copy Code
      // MathFuncsAssembly.cpp
      // compile with: /clr /LD
      
      #include "MathFuncsAssembly.h"
      
      namespace MathFuncs
      {
          double MyMathFuncs::Add(double a, double b)
          {
              return a + b;
          }
      
          double MyMathFuncs::Subtract(double a, double b)
          {
              return a - b;
          }
      
          double MyMathFuncs::Multiply(double a, double b)
          {
              return a * b;
          }
      
          double MyMathFuncs::Divide(double a, double b)
          {
              if (b == 0)
              {
                  throw gcnew DivideByZeroException("b cannot be zero!");
              }
      
              return a / b;
          }
      }
    4. Compile the class library by selecting Build Solution from the Build menu. This creates a dynamic link library (DLL) that can be used by other programs. For more information on DLLs, see DLLs.

    To create an application that references the class library

    1. To create an application that will reference and use the class library that you just created, from the File menu, select New and then select Project….
    2. On the Project types pane, under Visual C++, select CLR. This creates a project that targets the Common Language Runtime.
    3. On the Templates pane, select CLR Console Application.
    4. Choose a name for the project, such as MyExecRefsAssembly, and type it in the Name field. Next to Solution, select Add to Solution from the drop down list. This will add the new project to the same solution as the class library.
    5. Press OK to create the project.
    6. By default, when new projects are created, they are set up to use precompiled headers. To disable precompiled header, select Properties from the Project menu. Expand the Configuration Properties node, expand the C/C++ node, and then select Precompiled Headers. From the dropdown list next to Create/Use Precompiled Header, select Not Using Precompiled Header. Press OK to save these changes. For more information on precompiled headers, see Creating Precompiled Header Files.

    To use the functionality from the class library in the console application

    1. After you create a new CLR Console Application, a program is created for you that simply writes "Hello World" to the console. The name for the source file will be the same as the name you chose for the project above. In this example, it is named MyExecRefsAssembly.cpp.
    2. To use the math routines that were created in the class library, you must reference it. To do this, select References… from the Project menu. On the Property Pages dialog box, expand the Common Properties node and select References, and then select the Add New Reference… button. For more information about the References… dialog, see Framework and References, Common Properties, Property Pages Dialog Box.
    3. The Add Reference dialog is displayed. This dialog lists all the libraries that you can reference. The .NET tab lists the libraries that are included with the .NET Framework. The COM tab lists all the COM components on your computer. The Project tab lists all the projects in the current solution and any libraries they contain. On the Projects tab, select MathFuncsAssembly and then click OK. For more information about the Add Reference dialog, see Add Reference Dialog Box.
      Note:
      You can reference an assembly directly from the source file by including the #using directive, as in #using . For more information about this directive, see The #using Directive.
    4. You can now use the MyMathFuncs class in this application. In MyExecRefsAssembly.cpp, replace the contents of the file function with the following code:
      Copy Code
      // MyExecRefsAssembly.cpp
      // compile with: /clr /FUMathFuncsAssembly.dll
      
      using namespace System;
      
      int main(array ^args)
      {
          double a = 7.4;
          int b = 99;
      
          Console::WriteLine("a + b = {0}",
              MathFuncs::MyMathFuncs::Add(a, b));
          Console::WriteLine("a - b = {0}",
              MathFuncs::MyMathFuncs::Subtract(a, b));
          Console::WriteLine("a * b = {0}",
              MathFuncs::MyMathFuncs::Multiply(a, b));
          Console::WriteLine("a / b = {0}",
              MathFuncs::MyMathFuncs::Divide(a, b));
      
          return 0;
      }
    5. Build the executable by selecting Build Solution from the Build menu.

    To run the application

    1. Make sure MyExecRefsAssembly is selected as the default project. From the Solution Explorer, select MyExecRefsAssembly, and then select Set As StartUp Project from the Project menu.
    2. To run the project, select Start Without Debugging from the Debug menu. The output should look like this:
      Copy Code
      a + b = 106.4
      a - b = -91.6
      a * b = 732.6
      a / b = 0.0747474747474748


Be the first one to comment on this page.




  VC++ eBooks

No eBooks on VC++ could be found as of now.

 
 VC++ FAQs
More Links » »
 
 VC++ Interview Questions
More Links » »
 
 VC++ Articles
More Links » »
 
 VC++ News
More Links » »
 
 VC++ Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: bsd programming language, bsd language programming tutorial pdf, history of bsd programming, basic bsd programming, bsd band satellite programming, syntax use in bsd programming, bsd programming software download, turbo bsd programming, bsd programming code, learn bsd programming

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright © 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright © 2003-2017 Vyom Technosoft Pvt. Ltd., All Rights Reserved.