当前位置:网站首页>Dllexport et dllimport
Dllexport et dllimport
2022-07-03 14:34:00 【Vegetablessss】
InVSMoyenne,Si vous voulez utiliser des classes ou des variables à travers les projets,Il faut l'utiliser.dllexportEtdllimport,Voici quelques exemples de variables globales,Les fonctions et les classes sont utilisées entre les projets.
Préparation environnementale:UtiliserVSCréer un nouveauwindowsApplications etDLLProjets,windowsLe nom du projet de demande estConsoleApplication1,DLLLe nom du projet esttestExtern.

InConsoleApplication1Clic droit sur les propriétés de l'élément
Ajouter un répertoire de bibliothèque plustestExternGénérerdllEtlibRépertoire dans lequel
Dépendances supplémentaires plustestExtern.libNom
Variables globales
Dans le même projet, Les variables globales n'ont pas besoin d'être exportées ,extern Une déclaration suffit :
test.cppDéfinition moyenne:
int a = 100;
main.cppUtilisé dans:
extern int a;
int main()
{
cout << a << endl;
}
Produits100;
IntextExtern Définir des variables globales dans le projet ( Générer seulement si la macro d'exportation est définie libDocumentation), Vous devez l'exporter :
int _declspec(dllexport) sssss = 1000000;
InConsoleApplication1Utilisé danssssss Quand cette variable globale ,Vous devez importer:
extern int _declspec(dllimport) sssss;
int main()
{
cout << sssss << endl;
return 0;
}
Fonctions
Assurez - vous de déclarer l'exportation lors de la définition de la fonction :
void _declspec(dllexport) myFun()
{
std::cout << "myFun()" << std::endl;
}
Inmain.cpp Fichier d'en - tête contenant la Déclaration , Pour ne pas inclure de fichier d'en - tête extern Et déclarer l'importation
int main()
{
myFun();
return 0;
}
Catégorie
IntestExternDans le projetExportClass Doit être exporté au moment de la définition ,InConsoleApplication1 Doit contenir son fichier d'en - tête lorsqu'il est utilisé
class _declspec(dllexport) ExportClass
{
public:
void testExportClass();
};
void ExportClass::testExportClass()
{
std::cout << "textExportClass()" << std::endl;
}
main.cppMoyenne:
#include "C:\Users\Administrator\Documents\Visual Studio 2015\Projects\ConsoleApplication1\testExtern\extern.h"
int main()
{
ExportClass ex;
ex.testExportClass();
return 0;
}
边栏推荐
- Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
- C language,%d% Difference between 2D%2d%02d
- Sendmail can't send mail and it's too slow to send. Solve it
- MongoDB索引
- 修改数据库中的记录为什么报这个错
- Zzuli:1045 numerical statistics
- ShowMeBug入驻腾讯会议,开启专业级技术面试时代
- SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
- 基因家族特征分析 - 染色体定位分析
- Time conversion ()
猜你喜欢

分布式事务(Seata) 四大模式详解

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
![洛谷P4047 [JSOI2010]部落划分 题解](/img/7f/3fab3e94abef3da1f5652db35361df.png)
洛谷P4047 [JSOI2010]部落划分 题解

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

X86 assembly language - Notes from real mode to protected mode

Jiuyi cloud black free encryption free version source code

Mysql多表查询 #子查询

Programming language: the essence of type system

Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not

556. 下一个更大元素 III
随机推荐
Detailed explanation of four modes of distributed transaction (Seata)
556. 下一个更大元素 III : 简单构造模拟题
Find books ()
7-18 finding the single root of polynomial by dichotomy
7-3 count the number of words in a line of text
npm install卡住与node-npy的各种奇怪报错
Paper sharing: generating playful palettes from images
动态获取权限
添加Zabbix计算类型项目Calculated items
分布式事务(Seata) 四大模式详解
FPGA blocking assignment and non blocking assignment
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
Mysql多表查询 #子查询
adc128s022 ADC verilog设计实现
Why is this error reported when modifying records in the database
Zzuli:1046 product of odd numbers
556. 下一个更大元素 III
Add ZABBIX calculation type itemcalculated items
Time conversion ()
Get permissions dynamically