当前位置:网站首页>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
边栏推荐
- C语言力扣第61题之旋转链表。双端队列与构造循环链表
- 安装postgis时报找不到“POSTGIS_VERSION”这个函数
- 有一种密码学专用语言叫做ASN.1
- Fuzzy query of SQL
- Why do I delete the original record (OP d) and then add a new one in Kafka when I update MySQL data
- Interview notes of a company
- View partition table format
- LCA 板子
- Database SQL statement realizes function query of data decomposition
- MPU6050
猜你喜欢

HCIP BGP

C语言实现三子棋游戏(详解)

店铺排名问题,如何解决?

全屋WiFi方案:Mesh路由器组网和AC+AP

Three tier architecture of enterprise network

MPU6050

STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案

Install the laser of ROS_ scan_ Problems encountered in match library (I)

MySQL gets the maximum value record by field grouping

Function pointer and callback function
随机推荐
RMAN do not mark expired backups
Const read only variable constant
Openfeign asynchronous call problem
(.*?) regular expression
"Weilai Cup" 2022 Niuke summer multi school training camp 2H
对一个元素使用多种变形的方法
Don't the JDBC SQL connector of the big guys Flink now support all databases, such as vertica?
2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology
Function pointer and callback function
Svg -- loading animation
Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation
Methods of using multiple deformations on an element
MySQL gets the maximum value record by field grouping
Fu Yingna: Yuan universe is the new generation of Internet!
Opengauss pre check installation
The structure pointer must be initialized, and the pointer must also be initialized
Do you have a boss to help me check whether the parameter configuration of the Flink SQL connection Kafka authentication Kerberos is wrong
The difference between dynamic, VaR and object in fluent
[kvm] create virtual machine from kickstart file
SQL语句 关于字段转换怎么写