当前位置:网站首页>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

边栏推荐
猜你喜欢
随机推荐
Oracle null 有哪些注意事项【面试题】
电容器和电池有什么不同?
借助ginput函数在figure窗口实时读取、展示多条曲线的坐标值
自我监督学习和BERT模型
window下VS2022封装动态库以及调用动态库
东南亚跨境电商
自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema
@JsonProperty和JSONField的区别?
SAP HANA 新增一列时报错详解
Mysql 预准备语句详解(prepare、execute、deallocate)
ZEMAX | 在OpticStudio中建立扩增实境(VR)头戴式显示器
观看华为AI技术领域课程--深度学习前三章总结
微信小程序 自定义tabBar
opencv目标检测
C# Base64加密
二阶段提问总结
Oracle 分区索引详解(local、global)
九、请介绍类加载过程,什么是双亲委派模型?
Android学习 | 08.SQLiteOpenHelper
ARMv8 架构----armv8 类别








