Dela via


Creating Reusable Code (C++)

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

Next Steps

Previous: Resources for Creating a Game Using DirectX (C++) | Next: Walkthrough: Creating and Using a Dynamic Link Library (C++)

See Also

Tasks

Visual C++ Guided Tour