当前位置:网站首页>Dllexport and dllimport
Dllexport and dllimport
2022-07-03 14:34:00 【vegetablesssss】
stay VS in , If you want to use classes or variables across projects , It must be used dllexport and dllimport, The following are examples of global variables , Functions and classes are used across projects .
Environmental preparation : Use VS Create a new windows Applications and DLL project ,windows The application project name is ConsoleApplication1,DLL Project name: testExtern.

stay ConsoleApplication1 Right click item properties 
Additional library directories plus testExtern Generate dll and lib directory 
Additional dependencies plus testExtern.lib name
Global variables
In the same project , Global variables do not need to be exported ,extern Just make a statement :
test.cpp In the definition of :
int a = 100;
main.cpp Use in :
extern int a;
int main()
{
cout << a << endl;
}
Output 100;
stay textExtern Define global variables in the project ( Only when the export macro is defined will it generate lib file ), You need to export it :
int _declspec(dllexport) sssss = 1000000;
stay ConsoleApplication1 Use in sssss This global variable , You need to import :
extern int _declspec(dllimport) sssss;
int main()
{
cout << sssss << endl;
return 0;
}
function
Be sure to declare the export when defining the function :
void _declspec(dllexport) myFun()
{
std::cout << "myFun()" << std::endl;
}
stay main.cpp Contains the declared header file , If the header file is not included, you need extern And declare the import
int main()
{
myFun();
return 0;
}
class
stay testExtern In the project ExportClass Must be exported at definition , stay ConsoleApplication1 Must include its header file when used in
class _declspec(dllexport) ExportClass
{
public:
void testExportClass();
};
void ExportClass::testExportClass()
{
std::cout << "textExportClass()" << std::endl;
}
main.cpp in :
#include "C:\Users\Administrator\Documents\Visual Studio 2015\Projects\ConsoleApplication1\testExtern\extern.h"
int main()
{
ExportClass ex;
ex.testExportClass();
return 0;
}
边栏推荐
- 使用并行可微模拟加速策略学习
- tonybot 人形机器人 首次开机 0630
- Accelerating strategy learning using parallel differentiable simulation
- Find specified characters
- MongoDB数据库入门的常用命令
- Tonybot humanoid robot infrared remote control play 0630
- Although not necessarily the best, it must be the hardest!
- Sword finger offer 28 Symmetric binary tree
- Sendmail can't send mail and it's too slow to send. Solve it
- 超简单手机地图开发
猜你喜欢

Sword finger offer 28 Symmetric binary tree

Creation of data table of Doris' learning notes

puzzle(016.4)多米诺效应

7-18 finding the single root of polynomial by dichotomy

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

retrofit

X86 assembly language - Notes from real mode to protected mode

ShowMeBug入驻腾讯会议,开启专业级技术面试时代

一文了解微分段应用场景与实现机制

Understand the application scenario and implementation mechanism of differential segment
随机推荐
Luogu p3065 [usaco12dec]first! G problem solution
Add ZABBIX calculation type itemcalculated items
Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
Find the sum of the elements of each row of the matrix
Tonybot humanoid robot starts for the first time 0630
7-22 tortoise and rabbit race (result oriented)
Thread. Sleep and timeunit SECONDS. The difference between sleep
Jiuyi cloud black free encryption free version source code
Zzuli:1048 factorial table
7-9 one way in, two ways out (25 points)
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
超简单手机地图开发
tonybot 人形机器人 红外遥控玩法 0630
7-20 print 99 formula table (format output)
Niuke: crossing the river
基因家族特征分析 - 染色体定位分析
Creation of data table of Doris' learning notes
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
全文检索引擎Solr系列—–全文检索基本原理