当前位置:网站首页>Machine vision Series 2: vs DLL debugging
Machine vision Series 2: vs DLL debugging
2022-07-29 04:13:00 【Arvin L】
List of articles
Chapter one :Visual Studio 2019 Dynamic link library DLL establish
Chapter two :VS Dynamic link library DLL debugging
Catalog
1. Implicit call / Static call
1.2 To write C++ Debugging code
1.3 Change solution launch project
Preface
The last chapter is finished DLL The establishment of the , but DLL Only when called will it execute , This chapter records the use of C++ Item mode DLL The process of .
One 、 newly build C++ project ?
In the same solution explorer , Right-click the solution —— add to —— New projects —— Add empty items

Two 、 debugging DLL
1. Implicit call / Static call
1.1 File settings
hold DLL In the catalog .h Document and DLL Compile generated .lib File copy to C++ Project .cpp In the same directory

1.2 To write C++ Debugging code
Where changes need to be made
- Change the two introductions in the header
#include "dedip.h"
#pragma comment(lib, "dedip.lib")
- Change external functions
extern "C" __declspec(dllimport) bool eyeCloseCheck(BYTE*, int, int, int);
- Change the function when calling
cout << eyeCloseCheck(buffer, width, height, VailImgNum) << endl;
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <windows.h>
#include "dedip.h"
#pragma comment(lib, "dedip.lib")
#include <opencv2/dnn/dnn.hpp>
using namespace cv;
using namespace std;
extern "C" __declspec(dllimport) bool eyeCloseCheck(BYTE*, int, int, int);
int main()
{
Mat srcImg = imread("D:/ImgEnglish/redeye_img_test/1.bmp");
int width = srcImg.cols;
int height = srcImg.rows;
//imshow("1", srcImg);
//waitKey(0);
//DLL debugging
int length = (int)(srcImg.total() * srcImg.elemSize());
BYTE* buffer = new BYTE[length];
memcpy(buffer, srcImg.data, length * sizeof(BYTE));
int VailImgNum = 1;
cout << eyeCloseCheck(buffer, width, height, VailImgNum) << endl;
//imshow("2", OutImg);
//waitKey(0);
}
1.3 Change solution launch project
Right-click on the project —— Set as startup project

2. Explicit call
The display call is troublesome , Post a sample code , Own reference
The general idea is not to copy .h and .lib, One solution debug or release when , The generated files are in a folder .
#include <stdio.h>
#include <windows.h>
void main(void)
{
typedef int(*MyFunDll)(void);
HMODULE hdll = LoadLibrary("Win32Project1.dll"); // load dll file
if (hdll != NULL)
{
MyFunDll MyFunCall = (MyFunDll)GetProcAddress(hdll, "main");// Retrieve the address of the function to call
if (MyFunCall != NULL)
{
MyFunCall(); // Call the interface function
}
}
FreeLibrary(hdll); // Release dll file
}
adopt LoadLibrary() Function pair dll File to load ; Re pass GetProcAddress() Function to get the address of the interface function to be called ( In the example above MyFunCall To store the address of the interface function ); Then call the interface function (MyFunCall); Finally through FreeLibrary() Function pair dll File release . therefore , If it is used to load other dll file , The places that need to be changed in the above example are :
Loaded dll file name ( In the previous example "Win32Project1.dll");
Interface function name to retrieve ( In the previous example "main");
The format of the interface function called ( In the example above MyFunCall(), The parameter information of the function should be maintained with the interface function to be called "main" Agreement ).
summary
summary : Implicit call is more convenient to write code , But you need to copy the file again when there are changes .
quote :https://blog.csdn.net/weixin_44536482/article/details/91519413
C++ To write Dynamic link library dll and call dll- Experience in baidu (baidu.com)
边栏推荐
- C语言力扣第61题之旋转链表。双端队列与构造循环链表
- 数据库SQL语句实现数据分解的函数查询
- A little understanding of pointer, secondary pointer, wild pointer, pointer as function return value
- Leftmost prefix principle of index
- Whole house WiFi solution: mesh router networking and ac+ap
- SQL time fuzzy query datediff() function
- 伏英娜:元宇宙就是新一代互联网!
- JS realizes the function of one click Copy
- Class starts! See how smardaten decomposes complex business scenarios
- BIO、NIO、AIO的区别和原理
猜你喜欢
随机推荐
Function pointer and callback function
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
openFeign异步调用问题
C语言:联合体知识点总结
When defining an array, the size must be constant
Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
flink-sql 如何设置 sql执行超时时间
Svg -- loading animation
SQL server how to judge when the parameter received by the stored procedure is of type int?
The difference between dynamic, VaR and object in fluent
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
Codeforces Round #810 (Div. 2) D. Rain (线段树差分)
After I get the winfrom specific control ID from the database, I need to find the corresponding control through this ID and assign a value to the text text of the control. What should I do
Fu Yingna: Yuan universe is the new generation of Internet!
Wechat applet parameter transfer
How to solve the problem of store ranking?
LCA 板子
[deep learning CPU (part outside) - virtual memory]
这个报错是什么鬼啊,不影响执行结果,但是在执行sql时一直报错。。。连接maxComputer是使用
Summary on the thought of double pointer





![[principle] several ways of horizontal penetration](/img/fc/2ef7dd6ebc5c0bd8f7d302d8b596d6.png)



