Create DLL files

Author: John Pratt
Date Of Creation: 11 April 2021
Update Date: 1 July 2024
Anonim
How to Make & Use (.dll) files in Visual Studio | Using Class Library
Video: How to Make & Use (.dll) files in Visual Studio | Using Class Library

Content

DLL files are dynamically linked library files written and controlled with C ++. DLLs make sharing, storing and preserving your code easy. This wikiHow teaches you how to create a DLL file using Visual Studio on Windows, or Visual Studio on a Mac. Make sure you have "Desktop development with C ++" checked when you install. If you already have Visual Studio but haven't checked that box, you can run the installer again to make sure you have it.

To step

  1. Open Visual Studio. You can find this program in your Start menu or in the Applications folder. Since a DLL is a library of information, it is only part of a project and usually requires a companion app to access it.
    • You can download Visual Studio for Windows here: https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2019
    • You can download Visual Studio for Mac here: https://docs.microsoft.com/en-us/visualstudio/mac/installation?view=vsmac-2019
    • This wikiHow uses code provided by Microsoft to explain how to build a DLL file.
  2. Click on File. You can find this above the project room (Windows) or at the top of your screen (Mac).
  3. click on New and Project. The "Create New Project" dialog box appears.
  4. Suggest the options Language, Platform and Project type in. These will filter what types of project templates appear.
    • click on Language to get a drop-down menu and click C ++.
  5. click on Platform to get a drop-down menu and click Windows.
  6. click on Project type to get a drop-down menu and click Library.
  7. click on Dynamic-link Library (DLL). Your choice will turn blue. click on Next one to go on.
  8. Type a name for the project in the Name box. For example, type "MathLibrary" in the sample name box.
  9. click on To make. The DLL project is created.
  10. Add a header file to the DLL. You can do this by clicking Add new item below Project in the menu bar.
    • Select Visual C ++ in the left menu of the dialog box.
    • Select Header file (.h) in the center of the dialog box.
    • Type the name as "MathLibrary.h" in the name field below the menu choices.
    • click on Add to generate the empty header file.
  11. Type the following code in the empty header file.

      // MathLibrary. (n) is {n = 0, a // {n = 1, b // {n> 1, F (n-2) + F (n-1) // for some initial integral values ​​a and b. // If the sequence is initialized F (0) = 1, F (1) = 1, // then this relationship returns the well-known Fibonacci // row: 1, 1, 2, 3, 5, 8, 13, 21, 34, ... // Initialize a Fibonacci relationship string // such that F (0) = a, F (1) = b. // This function must be called before any other function. external "C" MATHLIBRARY_API void fibonacci_init (const unsigned long long a, const unsigned long long b); // Returns the next value in the row. // Returns True on success and updates the current value and index; // False on overflow, leave current value and index unchanged. external "C" MATHLIBRARY_API bole fibonacci_next (); // Get the current value in the row. external "C" MATHLIBRARY_API unsigned long long fibonacci_current (); // Get the position of the current value in the row. extern "C" MATHLIBRARY_API unsigned fibonacci_index ();

    • This is sample code from the Microsoft help website.
  12. Add a CPP file to the DLL. You can do this by clicking on Add new item below Project in the menu bar.
    • Select Visual C ++ in the left menu of the dialog box.
    • Select C ++ File (.cpp) in the center of the dialog box.
    • Type the name as "MathLibrary.cpp" in the name field below the menu choices.
    • click on Add to generate the empty file.
  13. Type the following code in the blank file.

      // MathLibrary.cpp: Defines the exported functions for the DLL. #include "stdafx.h" // use pch.h in Visual Studio 2019 #include utility> #include limits.h> #include "MathLibrary.h" // DLL internal state variables: static unsigned long long previous_; // Previous value, if present static unsigned long long current_; // Current string value static unsigned index_; // current seq. position // Initialize a Fibonacci relationship sequence // such that F (0) = a, F (1) = b. // This function must be called before any other function. void fibonacci_init (const unsigned long long a, const unsigned long long b) {index_ = 0; current_ = a; previous_ = b; // see special case when initialized} // Produce the next value in the sequence. // Returns true on success, false on overflow. bool fibonacci_next () {// check for overflow of result or position if ((ULLONG_MAX - previous_ current_) || (UINT_MAX == index_)) {return false; } // Special case when index == 0, just return b value if (index_> 0) {// else, calculate next sequence value previous_ + = current_; } std :: swap (current_, previous_); ++ index_; return true; } // Get the current value in the string. unsigned long long fibonacci_current () {return current_; } // Get the current index position in the row. unsigned fibonacci_index () {return index_; }

    • This is sample code from the Microsoft help website.
  14. click on Compile in the menu bar. You can find this button above the project field (Windows) or at the top of your screen (Mac).
  15. click on Compile solution. After clicking on that, you should see text like below:

      1> ------ Build started: Project: MathLibrary, Configuration: Debug Win32 ------ 1> MathLibrary.cpp 1> dllmain.cpp 1> Generating Code ... 1> Creating library C: Users username Source Repos MathLibrary Debug MathLibrary.lib and object C: Users username Source Repos MathLibrary Debug MathLibrary.exp 1> MathLibrary.vcxproj -> C: Users username Source Repos MathLibrary Debug MathLibrary.dll 1> MathLibrary.vcxproj -> C: Users username Source Repos MathLibrary Debug MathLibrary.pdb (Partial PDB) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    • If you succeeded in creating your DLL, you will see it here. If an error has occurred, it will be listed here so you can fix it.