DLL encapsulation and invocation of "C + +" multiple classesCategory: "Programming language"2012-07-11 18:53 6399 people read review (a) collection report dllc++includebuild2010
Directory (?) [+]
Most of the online tutorial is to encapsulate functions as DLLs, and the encapsulation of classes is basically similar.
Creating DLLs
Create a new Win32->dll project in the VS2010. As I set up the project named Facedll
Add facedll.h header file (the interface that defines the DLL, which is used when called)
[CPP]View Plaincopy
- #pragma once
- #ifdef Facelibdll
- #define FACEAPI _declspec (dllexport)
- #else
- #define FACEAPI _declspec (dllimport)
- #endif
- You can include header files that you need to use
- #include <opencv2/opencv.hpp>
- Class Faceapi Facerecognizer
- {
- Public
- Facerecognizer ();
- ~facerecognizer ();
- /////////////////////////////////////
- Functions of the class
- };
The function implementation is then written in Facedll.cpp and is defined as Facelibdll
[CPP]View Plaincopy
- #define FaceLIBDLL
-
- #include "stdafx.h"
- #include "facedll.h" &NBSP;&NBSP;
- #include <opencv2/opencv.hpp>
-
- //////////the implementation of functions in the header file
- Facerecognizer::facerecognizer ()
- {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
-
- }
-
- facerecognizer::~facerecognizer ()
- {
- &NBSP;&NBSP;
- }
Build project, the corresponding DLL and LIB files will be generated in the Debug folder: Facedll.dll facedll.lib
Multiple classes encapsulate DLLs
After encapsulating a class, the following class can invoke the DLL generated by the class, and then encapsulate the DLL for the new class.
You need to add header files, such as facedll.h, that need to be referenced in your project. Copy the Facedll.lib file in Debug. In properties->linker->input-> Additional dependecies add facedll.lib (or write full path: "... \debug\facedll.lib ")
And then the same way to encapsulate the new class is the ~
[CPP]View Plaincopy
- #pragma once
- #ifdef Heartlibdll
- #define HEARTAPI _declspec (dllexport)
- #else
- #define HEARTAPI _declspec (dllimport)
- #endif
- #include <opencv2/opencv.hpp>
- #include "facedll.h"
- #include "datadll.h"
- Class Heartapi Hrmeasure
- {
- };
Calling DLL calls requires the. h,. dll,. lib files for each DLL. Add a header file to your project and include it where you need it. The Lib file is copied to the project and written in Properties->linker->input-> Additional dependecies: Facedll.lib;heartdll.lib. or write in the program:
[CPP]View Plaincopy
- #pragma comment (lib, "Facedll.lib")
- #pragma comment (lib, "Heartdll.lib")
Classes that are encapsulated into DLLs can then be used directly in the program:
[CPP]View Plaincopy
- Hrmeasure *hrmea=New Hrmeasure ();
DLL encapsulation and invocation of "C + +" multiple classes