win10 c++的动态库的封装与调用示例

动态库dll工程下:testClass:的

testClass.h

 1 #ifndef TEST_CLASS_H_
 2 #define TEST_CLASS_H_
 3 
 4 #include <iostream>
 5 #include <string>
 6 
 7 using namespace std;
 8 
 9 #ifdef SERVERDLL_EXPORTS
10 #define SERVERDLL_API __declspec(dllexport)
11 #else
12 #define SERVERDLL_API __declspec(dllimport)
13 #endif
14 
15 class SERVERDLL_API TestClass
16 {
17 
18 public:
19 
20     virtual void VirtualFunction(const string& model_file, 
21         const string& trained_file, 
22         const string& mean_file);
23 
24     void NormalFunction(void);
25 
26 };
27 
28 SERVERDLL_API void func(void);
29 
30 #endif
View Code

testClass.cpp

 1 #include "testClass.h"
 2 
 3 void TestClass::VirtualFunction(const string& model_file, const string& trained_file, const string& mean_file)
 4 {
 5     std::cout << "modelfile=" << model_file << std::endl;
 6     std::cout << "modelfile=" << trained_file << std::endl;
 7     std::cout << "modelfile=" << mean_file << std::endl;
 8 
 9 }
10 
11 void TestClass::NormalFunction(void)
12 {
13     std::cout << "this is NormalFunction()!" << std::endl;
14     return;
15 }
16 
17 void func(void)
18 {
19     cout << "xixihaha" << endl;
20     return;
21 }
View Code

动态库的测试工程testClassDll下

testClass.h

 1 #ifndef TEST_CLASS_H_
 2 #define TEST_CLASS_H_
 3 
 4 #include <iostream>
 5 #include <string>
 6 
 7 using namespace std;
 8 
 9 #ifndef SERVERDLL_EXPORTS
10 #define SERVERDLL_API __declspec(dllexport)
11 #else
12 #define SERVERDLL_API __declspec(dllimport)
13 #endif
14 
15 class SERVERDLL_API TestClass
16 {
17 public:
18     virtual void VirtualFunction(const string& model_file, const string& trained_file, const string& mean_file);
19 
20     void NormalFunction(void);
21 };
22 
23 SERVERDLL_API void func(void);
24 
25 #endif
View Code

main.cpp

 1 #include "testClass.h"
 2 #include <iostream>
 3 //#include <Windows.h>
 4 using namespace std;
 5 
 6 #pragma comment(lib,"F:\\codePro\\VS2015_pro\\dllTest\\testClass\\testClassDll\\testClass.lib")
 7 
 8 int main()
 9 {
10     TestClass object;
11     std::string model_file("C:\\Caffedllcpu\\MultiClassificationChen\\model\\deploy.prototxt");
12     std::string trained_file("C:\\Caffedllcpu\\MultiClassificationChen\\model\\Train.caffemodel");
13     std::string mean_file("C:\\Caffedllcpu\\MultiClassificationChen\\model\\MeanFile.binaryproto");
14 
15     object.NormalFunction();
16     object.VirtualFunction(model_file, trained_file, mean_file);
17 
18     func();
19 
20     system("pause");
21 
22     return 0;
23 
24 }
View Code

 

posted @ 2023-05-22 15:42  赵家小伙儿  阅读(54)  评论(0编辑  收藏  举报