In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use VS2015 to create and use dynamic link libraries. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Let's first demonstrate how to create a dynamic link library using VS2015.
1. Create a new Win32 console Application, name is MathFuncsDll, solution name is DynamicLibrary, and click OK.
two。 Click next, select DLL for Application Type, check empty Project for additional options, and click finish.
3. Add the header file MathFuncsDll.h to the project "MathFuncsDll" under the solution "DynamicLibrary", as follows:
# pragma once
/ / MathFuncsDll.hnamespace MathFuncs {class MyMathFuncs {public:// Returns a + bstatic _ declspec (dllexport) double Add (double a, double b); / / Returns a-bstatic _ declspec (dllexport) double Subtract (double a, double b); / / Returns a * bstatic _ declspec (dllexport) double Multiply (double a, double b); / / Returns a / bmax / Throws DivideByZeroException if b is 0static _ declspec (dllexport) double Divide (double a, double b);}
PS: the modifier _ _ declspec (dllexport) enables DLL to export this method for use by other applications
4. Add the source file MathFuncsDll.cpp to the project "MathFuncsDll" under the solution "DynamicLibrary" as follows:
/ MathFuncsDll.cpp#include # include "MathFuncsDll.h" using namespace std;namespace MathFuncs {double MyMathFuncs::Add (double a, double b) {return a + b;} double MyMathFuncs::Subtract (double a, double b) {return a-b;} double MyMathFuncs::Multiply (double a, double b) {return a * b;} double MyMathFuncs::Divide (double a, double b) {if (b = = 0) {throw new invalid_argument ("b cannot be zero!");} return a / b;}}
5. Right-click the project MathFuncsDll, select Properties, select General under configuration Properties in the left pane, and in the right pane, change the configuration Type to dynamic Library (.dll). Click OK to save your changes.
6. Press Ctrl+B to compile and generate the dynamic link library, or click the build solution menu on the build menu.
At this point, a dynamic link library is created, and we can copy the header file and the generated dynamic link library file to the specified directory.
Let's demonstrate how to use VS2015 to reference dynamic link libraries.
1. Right-click the solution name DynamicLibrary, add, New Project, win32 console Application, name MyExecRefsDll, OK.
two。 Click next, select console applications under Application types, uncheck precompiled headers under additional options, and click finish.
PS: you can create an empty source program MyExecRefsDll.cpp in this way.
3. Configure to reference a dynamic link library. Right-click "reference" under the project MyExecRefsDll, select "add reference", check MathFuncsDll in the list, and OK.
4. Add the header file path of the dynamic link library. Right-click the project MyExecRefsDll, click the "General" option under the "configuration Properties" node on the left, and type the path where the MathFuncsDll.h header file is located (such as E:\ workplace\ DllDemo\ DynamicLibrary\ MathFuncsDll) in the range of "additional include directory" on the right.
5. Add the path to the dynamic link library file. Click the debug option under configuration Properties on the left, and type PATH=, in the Environment field on the right. For example, the actual path to MathFuncsDll.dll here is PATH=E:\ workplace\ DllDemo\ DynamicLibrary\ Release\ MathFuncsDll.dll, and click OK.
6. Copy the following code to MyExecRefsDll.cpp to overwrite the original content:
/ / MyExecRefsDll.cpp// compile with: / EHsc / link MathFuncsDll.lib#include # include "MathFuncsDll.h" using namespace std;int main () {double a = 7.4 nint b = 99 witcout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.