当前位置:网站首页>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;
}
边栏推荐
- X86 assembly language - Notes from real mode to protected mode
- Preliminary summary of structure
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
- 分布式事务(Seata) 四大模式详解
- Find the sum of the elements of each row of the matrix
- Add ZABBIX calculation type itemcalculated items
- [qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
- ConstraintLayout 的使用
- String substitution
猜你喜欢
Luogu p4047 [jsoi2010] tribal division solution
Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules
Pyqt interface production (login + jump page)
NPM install is stuck with various strange errors of node NPY
Showmebug entered Tencent conference, opening the era of professional technical interview
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
retrofit
编程语言:类型系统的本质
retrofit
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
随机推荐
7-19 check denomination (solve binary linear equation)
Eight sorts
NPM install is stuck with various strange errors of node NPY
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
Output student grades
Sendmail can't send mail and it's too slow to send. Solve it
1017 a divided by B (20 points)
Although not necessarily the best, it must be the hardest!
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库
Get permissions dynamically
数学常数表 by q779
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
表单文本框的使用(一) 选择文本
Thread. Sleep and timeunit SECONDS. The difference between sleep
Recent learning summary
Detailed explanation of four modes of distributed transaction (Seata)
Find books ()
洛谷P4047 [JSOI2010]部落划分 题解
The mail function of LNMP environment cannot send mail