当前位置:网站首页>Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
2022-07-29 04:12:00 【Arvin L】
List of articles
Chapter one :Visual Studio 2019 Dynamic link library DLL establish
Catalog
Preface
Recently started a medical machine vision project , Need to use C++, Record some key points .
Environmental Science :Windows10, VS2019,opencv320
One 、DLL What is it? ?
Dynamic link library DLL Are some independent documents , It contains programs that can be executed or other dll Call a function to do something , Only when other modules call dll Function in ,dll To work . In actual programming , We can put the function to complete a function in a dynamic link library , And then provide it to other programs to call . image Windows API All the functions in are contained in dll in , Such as Kernel32.dll, User32.dll, GDI32.dll etc. .
Two 、 Establishment steps
1. install VS
Official website , The latest version is 2022
Visual Studio 2022 IDE - Programming tools for software developers (microsoft.com)
2. establish DLL library
The code is as follows ( Example ):
1, New projects
2, Select dynamic link library (DLL)
3, Set project name , If there is no special need, do not check ( Put the solution and project in the same directory )
4, Generate default file , There is no need to modify .
5, Use the property manager to configure properties , For details, see Chapter 2 of the series .
6, Modify the precompiled header , Property page ——C/C++—— Precompiled translation head —— Not applicable to precompiled header .
notes : If the program is not modified, an error will be reported , I will study it later
3、 ... and 、 newly build DLL
1, Under the project header , Right click new header (.h), Used to declare the function interface to be exported .
2, Source files under the project , Right click new source file (.cpp), Used to implement the declared function .
The project catalogue is as follows :
Now you can write code .
.h file
The function of the following code is to declare a function that can be called “SayHello()”, Its return type is void.
#pragma once
#include <iostream>
extern "C" __declspec(dllexport) void SayHello();
Now analyze extern "C" __declspec(dllexport) void SayHello(); This code , among extern "C" The function of is to tell the compiler to press C Language , The significance of doing so is not discussed here , If you are interested, you can inquire by yourself . Then analysis __declspec(dllexport), This modifier tells the compiler and linker that the function or variable it modifies needs to be from DLL export , For use by other applications ; In contrast, another code is __declspec(dllimport), The purpose of this modifier is to tell the compiler and linker that the function or variable modified by it needs to be from DLL Import , It will also be used later . Finally, the function void SayHello(), It is the function that needs to be called by other programs .
.cpp file
Realization .h Functions declared in the file
#include "pch.h"
#include "TestDLL.h"
void SayHello()
{
std::cout << "Hello! You did it !" << std::endl;
}
Code writing completed .
Four 、 compile DLL
If the attribute environment is ok , Click on the compilation
Click compile to pop up below , Click on the confirmation (DLL Will not generate exe, Ignore the error report )
In the project path ——x64——debug Generate files under folder .
Compile the complete .
summary
1、 The above tutorial is only applicable to debugging mode , If you want to start directly TestDLLCreated.exe Applications , You still need to “TestDLL.dll” and “TestDLL.lib” Copy the file to TestDLLCreated.exe Only under the same directory can it run !
2、 You can use the property manager to configure properties , Other items can use attributes directly , Avoid duplicate settings .
Reference resources :https://blog.csdn.net/elaine_bao/article/details/51784864
边栏推荐
- Function pointer and callback function
- Leftmost prefix principle of index
- 力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)
- HCIP BGP
- The function "postgis_version" cannot be found when installing PostGIS
- 安装ros的laser_scan_matche库所遇到的问题(一)
- Nacos registry
- Solution: module 'xlrd' has no attribute 'open_ Error reporting of workbook '
- 数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
- Is the browser multi process or single process?
猜你喜欢
Deep understanding of browser caching mechanism (HTTP)
安装ros的laser_scan_matche库所遇到的问题(一)
小程序:区域滚动、下拉刷新、上拉加载更多
When array is used as a function parameter, it is better to use the array size as a function parameter
rman不标记过期备份
Object array merges elements according to a field
C语言力扣第61题之旋转链表。双端队列与构造循环链表
Design of environment detection system based on STM32 and Alibaba cloud
Data mining -- Introduction to the basis of association analysis (Part 1)
Mmdetection preliminary use
随机推荐
Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理
Codeforces Round #810 (Div. 2) D. Rain (线段树差分)
Data mining -- Introduction to the basis of association analysis (Part 1)
The data source is SQL server. I want to configure the incremental data of the last two days of the date field updatedate to add
Fuzzy query of SQL
Install the laser of ROS_ scan_ Problems encountered in match library (I)
Methods of using multiple deformations on an element
SQL语句 关于字段转换怎么写
[Openstack] keystone,nova
opengauss预检查安装
RMAN do not mark expired backups
Compilation and linking
MPU6050
Routing knowledge
开课!看smardaten如何分解复杂业务场景
LCA board
Pointer variables -printf%d and%p meaning
Basic configuration of BGP - establish peers and route announcements
Database SQL statement realizes function query of data decomposition
What the hell is this error? It doesn't affect the execution result, but it always reports errors when executing SQL... Connecting maxcomputer uses