当前位置:网站首页>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;
}
边栏推荐
- Pyqt interface production (login + jump page)
- C language,%d% Difference between 2D%2d%02d
- Etcd cluster permission management and account password usage
- Zzuli:1041 sum of sequence 2
- x86汇编语言-从实模式到保护模式 笔记
- retrofit
- Table of mathematical constants by q779
- Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
- 基因家族特征分析 - 染色体定位分析
- Thread.sleep和TimeUnit.SECONDS.sleep的区别
猜你喜欢
tonybot 人形机器人 定距移动 代码编写玩法
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
剑指 Offer 28. 对称的二叉树
分布式事务(Seata) 四大模式详解
洛谷P4047 [JSOI2010]部落划分 题解
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
Detailed explanation of four modes of distributed transaction (Seata)
Leetcode (4) -- find the median of two positively ordered arrays
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
随机推荐
How to query the baby category of tmall on Taobao
Statistical capital consonants
提高效率 Or 增加成本,开发人员应如何理解结对编程?
论文分享:Generating Playful Palettes from Images
DDK for XP
7-1 positive integer a+b (15 points)
Analysis of gene family characteristics - chromosome location analysis
一文了解微分段应用场景与实现机制
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
7-4 BCD decryption (10 points)
China PETG market forecast and Strategic Research Report (2022 Edition)
修改数据库中的记录为什么报这个错
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Luogu p4047 [jsoi2010] tribal division solution
C language,%d% Difference between 2D%2d%02d
NPM install is stuck with various strange errors of node NPY
X86 assembly language - Notes from real mode to protected mode
556. 下一个更大元素 III : 简单构造模拟题
Zzuli:1040 sum of sequence 1
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)