0% found this document useful (0 votes)
42 views7 pages

Diagrma de Distribucion

This document provides a step-by-step guide to creating a dynamic link library (DLL) in C++ using Visual Studio. It describes creating a DLL project that implements some math functions, and a console app project that uses the functions from the DLL. The guide covers adding exported functions to the DLL, importing and using them in the console app, and running the completed app. It also provides some background on DLLs and the extensions used in Visual Studio to support their creation and use.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views7 pages

Diagrma de Distribucion

This document provides a step-by-step guide to creating a dynamic link library (DLL) in C++ using Visual Studio. It describes creating a DLL project that implements some math functions, and a console app project that uses the functions from the DLL. The guide covers adding exported functions to the DLL, importing and using them in the console app, and running the completed app. It also provides some background on DLLs and the extensions used in Visual Studio to support their creation and use.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Walkthrough: Create and use your own Dynamic Link Library (C++)

 08/21/2019
 23 minutes to read

o

o
o
+4

This step-by-step walkthrough shows how to use the Visual Studio IDE to create your own dynamic link library (DLL) written in Microsoft C++ (MSVC).
Then it shows how to use the DLL from another C++ app. DLLs (also known as shared libraries in UNIX-based operating systems) are one of the most
useful kinds of Windows components. You can use them as a way to share code and resources, and to shrink the size of your apps. DLLs can even make it
easier to service and extend your apps.

In this walkthrough, you'll create a DLL that implements some math functions. Then you'll create a console app that uses the functions from the DLL. You'll
also get an introduction to some of the programming techniques and conventions used in Windows DLLs.

This walkthrough covers these tasks:

 Create a DLL project in Visual Studio.


 Add exported functions and variables to the DLL.
 Create a console app project in Visual Studio.
 Use the functions and variables imported from the DLL in the console app.
 Run the completed app.

Like a statically linked library, a DLL exports variables, functions, and resources by name. A client app imports the names to use those variables, functions,
and resources. Unlike a statically linked library, Windows connects the imports in your app to the exports in a DLL at load time or at run time, instead of
connecting them at link time. Windows requires extra information that isn't part of the standard C++ compilation model to make these connections. The
MSVC compiler implements some Microsoft-specific extensions to C++ to provide this extra information. We explain these extensions as we go.

This walkthrough creates two Visual Studio solutions; one that builds the DLL, and one that builds the client app. The DLL uses the C calling convention. It
can be called from apps written in other programming languages, as long as the platform, calling conventions, and linking conventions match. The client
app uses implicit linking, where Windows links the app to the DLL at load-time. This linking lets the app call the DLL-supplied functions just like the
functions in a statically linked library.

This walkthrough doesn't cover some common situations. The code doesn't show the use of C++ DLLs by other programming languages. It doesn't show
how to create a resource-only DLL, or how to use explicit linking to load DLLs at run-time rather than at load-time. Rest assured, you can use MSVC and
Visual Studio to do all these things.

For links to more information about DLLs, see Create C/C++ DLLs in Visual Studio. For more information about implicit linking and explicit linking,
see Determine which linking method to use. For information about creating C++ DLLs for use with programming languages that use C-language linkage
conventions, see Exporting C++ functions for use in C-language executables. For information about how to create DLLs for use with .NET languages,
see Calling DLL Functions from Visual Basic Applications.

Prerequisites
 A computer that runs Microsoft Windows 7 or later versions. We recommend Windows 10 for the best development experience.

 A copy of Visual Studio. For information on how to download and install Visual Studio, see Install Visual Studio. When you run the installer, make
sure that the Desktop development with C++ workload is checked. Don't worry if you didn't install this workload when you installed Visual Studio.
You can run the installer again and install it now.

 An understanding of the basics of using the Visual Studio IDE. If you've used Windows desktop apps before, you can probably keep up. For an
introduction, see Visual Studio IDE feature tour.
 An understanding of enough of the fundamentals of the C++ language to follow along. Don't worry, we don't do anything too complicated.

Create the DLL project


In this set of tasks, you create a project for your DLL, add code, and build it. To begin, start the Visual Studio IDE, and sign in if you need to. The
instructions vary slightly depending on which version of Visual Studio you're using. Make sure you have the correct version selected in the control in the
upper left of this page.

To create a DLL project in Visual Studio 2019

1. On the menu bar, choose File > New > Project to open the Create a New Project dialog box.
2. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.
3. From the filtered list of project types, select Dynamic-link Library (DLL), and then choose Next.
4. In the Configure your new project page, enter MathLibrary in the Project name box to specify a name for the project. Leave the
default Location and Solution name values. Set Solution to Create new solution. Uncheck Place solution and project in the same directory if
it's checked.
5. Choose the Create button to create the project.

When the solution is created, you can see the generated project and source files in the Solution Explorer window in Visual Studio.
Right now, this DLL doesn't do very much. Next, you'll create a header file to declare the functions your DLL exports, and then add the function definitions
to the DLL to make it more useful.

To add a header file to the DLL

1. To create a header file for your functions, on the menu bar, choose Project > Add New Item.
2. In the Add New Item dialog box, in the left pane, select Visual C++. In the center pane, select Header File (.h). Specify MathLibrary.h as the name
for the header file.
3. Choose the Add button to generate a blank header file, which is displayed in a new editor window.

LEYENDA DE DISTRIBUCIÓN LEYENDA DE DISTRIBUCIÓN


Nº DESCRIPCIÓN Nº DESCRIPCIÓN
01 01

02 02

03 03

04 04

05 05
06 06

07 07

08 08

LEYENDA DE DISTRIBUCIÓN LEYENDA DE DISTRIBUCIÓN


Nº DESCRIPCIÓN Nº DESCRIPCIÓN
01 01

02 02

03 03

04 04

05 05

06 06

07 07

08 08

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy