当前位置:网站首页>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;
}
边栏推荐
- Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
- ConstraintLayout 的使用
- 【7.3】146. LRU caching mechanism
- Understand the application scenario and implementation mechanism of differential segment
- 【7.3】146. LRU缓存机制
- 洛谷P5536 【XR-3】核心城市 题解
- MongoDB数据库入门的常用命令
- 556. 下一个更大元素 III
- Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
- Too many files with unapproved license
猜你喜欢

npm install卡住与node-npy的各种奇怪报错

tonybot 人形机器人 首次开机 0630

retrofit

Understand the application scenario and implementation mechanism of differential segment

Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million

Jiuyi cloud black free encryption free version source code

Puzzle (016.3) is inextricably linked
![洛谷P4047 [JSOI2010]部落划分 题解](/img/7f/3fab3e94abef3da1f5652db35361df.png)
洛谷P4047 [JSOI2010]部落划分 题解

Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things

puzzle(016.3)千丝万缕
随机推荐
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
China PETG market forecast and Strategic Research Report (2022 Edition)
动态获取权限
Why is this error reported when modifying records in the database
Paper sharing: generating playful palettes from images
Table of mathematical constants by q779
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
Luogu p4047 [jsoi2010] tribal division solution
Puzzle (016.4) domino effect
Programming language: the essence of type system
Puzzle (016.3) is inextricably linked
适用于XP的DDK
ConstraintLayout 的使用
7-17 crawling worms (break exercise)
Zzuli:1048 factorial table
Preliminary summary of structure
Leetcode (4) -- find the median of two positively ordered arrays
7-22 tortoise and rabbit race (result oriented)
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
tonybot 人形机器人 查看端口并对应端口 0701