当前位置:网站首页>VS2022 encapsulation under Windows dynamic library and dynamic library calls
VS2022 encapsulation under Windows dynamic library and dynamic library calls
2022-08-03 06:10:00 【Shiyu】
First, create a new project MyLib (encapsulate your own dynamic library)
1. Header file Test.h: (_declspec(dllexport) should be placed in front of the exported class name, indicating that the package should be exported to the library)
#pragma onceclass _declspec(dllexport) Test{public:void say();};2. Source file Test.cpp:
#include "Test.h"#includevoid Test::say() {std::cout << "Hello! My name is linyu!" << std::endl;} 3. Right-click on project properties -> configuration properties -> configuration type (modified to dynamic library.dll):

4. Right-click to generate, a dynamic library will be generated (two files will be generated, one is dll, the other is lib, lib is the index address information of the function entry, and the dll is the real implementation of the function)

Second, create a new project TestMyLib (call the library just packaged)
1. Copy the header file Test.h to the source file directory of the project

2. Go back to the project, header file -> right click -> add existing item Test.h

3. Copy the dynamic library file MyLib.dll to the directory where the exe is generated:

4. Linker->General->Additional library directory, link to the directory where MyLib.lib is located:

5. Linker->Input->Additional dependencies, add the generated library name MyLib.lib

6. Write the TestMyLib.cpp file:
#include #include "Test.h"int main(){Test t;t.say();} 7. Click to run

边栏推荐
猜你喜欢
随机推荐
SAP HANA 新增一列时报错详解
梯度下降、反向传播
Kettle 从资源库中载入新的转换出错(Invalid byte 1 of 1-byte UTF-8 sequence)
c#,.net 下载文件 设置断点
寄存器常见指令
MATLAB给多组条形图添加误差棒
设备树(devicetree)-dts语法
二、Exception和Error有什么区别?
Qlik Sense 字符串截取和拼接详解(Left、Right、&)
classpath:与classpath*的比较
神经网络基础
ZEMAX | 在 OpticStudio 中使用自由曲面进行设计
[XSS, file upload, file inclusion]
【第四周】MobileNet和HybridSN
动漫:海贼王女
ZEMAX | 探索 OpticStudio中的序列模式
ZEMAX | 探究 OpticStudio 偏振分析功能
采用Trench肖特基二极管,实现功率密度的显著提升
ASP.NET MVC3的伪静态实现
稳压二极管的工作原理及稳压二极管使用电路图








