In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to create and invoke C++ DLL dynamic library". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Create a library project
2. Add header files
ClassDll.h
/ / Macro definitions prevent repeated compilation of .h files # ifndef _ DLLCLASS_H#define _ DLLCLASS_H// dll library files define macros (DLLCLASS_EXPORTS) use _ declspec (dllexport) / / when using dll library files _ declspec (dllimport) (without defining macros) # ifdef DLLCLASS_EXPORTS#define EXT_CLASS _ declspec (dllexport) # else#define EXT_CLASS _ declspec (dllimport) # endif// defines the class of the library file (export or import) class EXT_CLASS CMath {public: / / define the function int Add (int item1 Int item2) Int Sub (int item1, int item2);}; # endif3, add cpp file
ClassDll.cpp
/ / define the DLLCLASS_EXPORTS header file class / / use _ declspec (dllexport) to export # define DLLCLASS_EXPORTS#include "ClassDll.h" / / implement the class function int CMath::Add (int item1, int item2) {return item1 + item2;} int CMath::Sub (int item1, int item2) {return item1-item2;} 4, compile the dll project
Generate a file
5. Create a calling project
General engineering, multi-byte project
6. Call the project to add the cpp file
UseClassdll.cpp
# include using namespace std;// import header file library class uses _ declspec (dllimport) to export class # include ".. / ClassDll/ClassDll.h" / / implicitly call dll load library file # pragma comment (lib, ".. / Debug/ClassDll.lib") / / Runtime dll file and exe file in one folder int main () {/ / define class CMath math in dll library / / call the function int sum = math.Add (5,6); int sub = math.Sub (5,6); / / print the result cout
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: 202
*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.