Create C/C++ DLLs in Visual Studio (original) (raw)

In Windows, a dynamic-link library (DLL) is a kind of executable file that acts as a shared library of functions and resources. Dynamic linking is an operating system capability. It enables an executable to call functions or use resources stored in a separate file. These functions and resources can be compiled and deployed separately from the executables that use them.

A DLL isn't a stand-alone executable. DLLs run in the context of the applications that call them. The operating system loads the DLL into an application's memory space. It's done either when the application is loaded (implicit linking), or on demand at runtime (explicit linking). DLLs also make it easy to share functions and resources across executables. Multiple applications can access the contents of a single copy of a DLL in memory at the same time.

Differences between dynamic linking and static linking

Static linking copies all the object code in a static library into the executables that use it when they're built. Dynamic linking includes only the information needed by Windows at run time to locate and load the DLL that contains a data item or function. When you create a DLL, you also create an import library that contains this information. When you build an executable that calls the DLL, the linker uses the exported symbols in the import library to store this information for the Windows loader. When the loader loads a DLL, the DLL is mapped into the memory space of your application. If present, a special function in the DLL, DllMain, is called to do any initialization the DLL requires.

Differences between applications and DLLs

Even though DLLs and applications are both executable modules, they differ in several ways. The most obvious difference is that you can't run a DLL. From the system's point of view, there are two fundamental differences between applications and DLLs:

Advantages of using DLLs

Dynamic linking to code and resources offers several advantages over static linking:

A potential disadvantage to using DLLs is that the application isn't self-contained. It depends on the existence of a separate DLL module: one that you must deploy or verify yourself as part of your installation.

More information on how to create and use DLLs

The following articles provide detailed information about how to create C/C++ DLLs in Visual Studio.

Walkthrough: Creating and using a dynamic link library (C++)
Describes how to create and use a DLL using Visual Studio.

Kinds of DLLs
Provides information about the different kinds of DLLs that can be built.

DLL frequently asked questions
Provides answers to frequently asked questions about DLLs.

Link an executable to a DLL
Describes explicit and implicit linking to a DLL.

Initialize a DLL
Discusses DLL initialization code that must execute when your DLL loads.

DLLs and Microsoft C++ run-time library behavior
Describes the run-time library DLL startup sequence.

LoadLibrary and AfxLoadLibrary
Discusses using LoadLibrary and AfxLoadLibrary to explicitly link to a DLL at runtime.

GetProcAddress
Discusses using GetProcAddress to obtain the address of an exported function in the DLL.

FreeLibrary and AfxFreeLibrary
Discusses using FreeLibrary and AfxFreeLibrary when the DLL module is no longer needed.

Dynamic-Link Library Search Order
Describes the search path that the Windows operating system uses to locate a DLL on the system.

Module states of a regular MFC DLL dynamically linked to MFC
Describes the module states of a regular MFC DLL dynamically linked to MFC.

MFC extension DLLs
Explains DLLs that typically implement reusable classes derived from the existing MFC classes.

Creating a resource-only DLL
Discusses a resource-only DLL, which contains nothing but resources, such as icons, bitmaps, strings, and dialog boxes.

Localized resources in MFC Applications: Satellite DLLs
Provides enhanced support for satellite DLLs, a feature that helps in creating applications localized for multiple languages.

Importing and exporting
Describes importing public symbols into an application or exporting functions from a DLL

Active technology and DLLs
Allows object servers to be implemented inside a DLL.

Automation in a DLL
Describes what the Automation option in the MFC DLL Wizard supplies.

Naming conventions for MFC DLLs
Discusses how the DLLs and libraries included in MFC follow a structured naming convention.

Calling DLL functions from Visual Basic applications
Describes how to call DLL functions from Visual Basic applications.

Using MFC as part of a DLL
Describes regular MFC DLLs, which let you use the MFC library as part of a Windows dynamic-link library.

DLL version of MFC
Describes how you can use the MFCxx.dll and MFCxxD.dll (where x is the MFC version number) shared dynamic-link libraries with MFC applications and MFC extension DLLs.