当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

7-15 calculation of PI

【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?

Accelerating strategy learning using parallel differentiable simulation

论文分享:Generating Playful Palettes from Images

X86 assembly language - Notes from real mode to protected mode

Niuke: crossing the river

retrofit

Tonybot humanoid robot starts for the first time 0630

提高效率 Or 增加成本,开发人员应如何理解结对编程?

Protobuf and grpc
随机推荐
LNMP环境mail函数不能发送邮件解决
添加Zabbix计算类型项目Calculated items
Too many files with unapproved license
Niuke: crossing the river
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
Strategy, tactics (and OKR)
Address book sorting
MySQL multi table query subquery
Zzuli:1047 logarithmic table
Although not necessarily the best, it must be the hardest!
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
Statistical capital consonants
Understand the application scenario and implementation mechanism of differential segment
Common shortcut keys in PCB
Adc128s022 ADC Verilog design and Implementation
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
X86 assembly language - Notes from real mode to protected mode
How Facebook moves instagram from AWS to its own server
Table of mathematical constants by q779
dllexport和dllimport