Diagrma de Distribucion
Diagrma de Distribucion
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.
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.
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.
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.
02 02
03 03
04 04
05 05
06 06
07 07
08 08
02 02
03 03
04 04
05 05
06 06
07 07
08 08