当前位置:网站首页>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 humanoid robot infrared remote control play 0630
- Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
- Tonybot humanoid robot starts for the first time 0630
- 适用于XP的DDK
- 1017 a divided by B (20 points)
- Mysql多表查询 #子查询
- MySQL multi table query subquery
- Stop asking yourself if you are suitable for software testing
- Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
- SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
猜你喜欢

Programming language: the essence of type system

亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?

dllexport和dllimport

剑指 Offer 28. 对称的二叉树

Showmebug entered Tencent conference, opening the era of professional technical interview

556. The next larger element III

Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs

Accelerating strategy learning using parallel differentiable simulation

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

puzzle(016.4)多米诺效应
随机推荐
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
7-19 check denomination (solve binary linear equation)
Selective sorting
Use of constraintlayout
tonybot 人形机器人 红外遥控玩法 0630
Eight sorts
Four data flows and cases of grpc
Common commands for getting started with mongodb database
全文检索引擎Solr系列—–全文检索基本原理
7-17 crawling worms (break exercise)
7-28 monkeys choose King (Joseph problem)
C language,%d% Difference between 2D%2d%02d
Find books ()
556. 下一个更大元素 III
Zzuli:1048 factorial table
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
String reverse order
7-23 currency conversion (using array conversion)
Zzuli:1045 numerical statistics
亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?