当前位置:网站首页>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
边栏推荐
- Solution: module 'xlrd' has no attribute 'open_ Error reporting of workbook '
- Don't the JDBC SQL connector of the big guys Flink now support all databases, such as vertica?
- Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
- Pointer of pointer???...
- 对一个元素使用多种变形的方法
- "Weilai Cup" 2022 Niuke summer multi school training camp 1 J serval and essay (heuristic merger)
- [paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation
- Routing knowledge
- 淘宝商品详情接口(商品详情页面数据接口)
- C language - character array - string array - '\0' -sizeof-strlen() -printf()
猜你喜欢

MPU6050

mmdetection初步使用

Nacos registry

First knowledge of C language (3)

Class starts! See how smardaten decomposes complex business scenarios

Note: restframe work records many to one tables, how to serialize in that table (reverse query)

Data mining -- Introduction to the basis of association analysis (Part 1)

BGP的基础配置---建立对等体、路由宣告

Basic configuration of BGP - establish peers and route announcements

Beginner: array & String
随机推荐
请问,在sql client中,执行insert into select from job时,如何单
Nacos registry
3. Solve pychart's error unresolved reference 'selenium' unresolved reference 'webdriver‘
Object array merges elements according to a field
Data mining -- Introduction to the basis of association analysis (Part 1)
Problems encountered in vscode connection SSH
【深度学习CPU(番外篇)——虚拟内存】
openFeign异步调用问题
Methods of using multiple deformations on an element
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
I. creation and constraint of MySQL table
Communication between parent-child components and parent-child components provide and inject
[untitled]
2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology
MPU6050
SQL server当存储过程接收的参数是int类型时,如何做判断?
Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?
HCIP BGP
How to query the submission number of a version
AssertionError(“Torch not compiled with CUDA enabled“)