最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

QT調(diào)用vs2019生成的c++動態(tài)庫的方法實現(xiàn)

 更新時間:2024年06月12日 11:16:11   作者:txwtech笛克特科  
本文主要介紹了QT調(diào)用vs2019生成的c++動態(tài)庫的方法實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

dll庫的創(chuàng)建方法:

VS2019創(chuàng)建c++動態(tài)鏈接庫dll與調(diào)用方法-CSDN博客

加減法示范:

頭文件

// 下列 ifdef 塊是創(chuàng)建使從 DLL 導(dǎo)出更簡單的
// 宏的標(biāo)準(zhǔn)方法。此 DLL 中的所有文件都是用命令行上定義的 DLL3_EXPORTS
// 符號編譯的。在使用此 DLL 的
// 任何項目上不應(yīng)定義此符號。這樣,源文件中包含此文件的任何其他項目都會將
// DLL3_API 函數(shù)視為是從 DLL 導(dǎo)入的,而此 DLL 則將用此宏定義的
// 符號視為是被導(dǎo)出的。
#ifdef DLL3_EXPORTS
#define DLL3_API __declspec(dllexport)
#else
#define DLL3_API __declspec(dllimport)
#endif

// 此類是從 dll 導(dǎo)出的
class DLL3_API CDll3 {
public:
	CDll3(void);
	int name;
	int age;

	// TODO: 在此處添加方法。
};

extern DLL3_API int nDll3;
extern DLL3_API CDll3;


	extern "C"
	{

		DLL3_API int fnDll3(void);
		DLL3_API int fnAdd(int a, int b);
		DLL3_API int fnSub(int a, int b);
	}



 cpp

// Dll3.cpp : 定義 DLL 的導(dǎo)出函數(shù)。
//

#include "pch.h"
#include "framework.h"
#include "Dll3.h"


// 這是導(dǎo)出變量的一個示例
DLL3_API int nDll3=666666;

// 這是導(dǎo)出函數(shù)的一個示例。

    DLL3_API int fnDll3(void)
    {
        return 666;
    }

    DLL3_API int fnAdd(int a, int b)
    {
        return a + b;
    }

    DLL3_API int fnSub(int a, int b)
    {
        return a - b;
    }



    


// 這是已導(dǎo)出類的構(gòu)造函數(shù)。
CDll3::CDll3()
{
    return;
}


每次修改后:都執(zhí)行-》重新生成,確保 dll和lib文件的同步更新

記得 選擇release,x64

把頭文件.h與dll,lib放在一個地方以便拷貝到QT項目

QT創(chuàng)建一個項目:

 把頭文件.h與dll,lib拷貝到項目文件夾里面

構(gòu)建編譯:

查看默認編譯后的路徑:

 拷貝到lib,和dll到exe生成的目錄

QT顯式調(diào)用dll

cpp主文件添加頭文件:

構(gòu)造函數(shù)添加代碼:

dll隱式調(diào)用 

pro文件添加:修改Dll3, Dll3表示Dll3.lib

就可以直接調(diào)用了:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLibrary>
#include <iostream>
#include <QMessageBox>
#include "Dll3.h"
#include <QDebug>
typedef int ( *pAdd)(int , int); //定義函數(shù)指針
using namespace std;
//using namespace MathFunc;

//extern "C" __declspec(dllexport) int fnAdd(int a, int b);


//extern "C" __declspec(dllexport) int fnAdd(int a, int b);

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


   //dll隱式調(diào)用

    int cc = fnAdd(2,6);
    qDebug()<<"cc value is :"<<QString::number(cc);
    int cc_sub = fnSub(2,6);
    qDebug()<<"cc_sub value is :"<<QString::number(cc_sub);
    int n_dll3 = nDll3;
    qDebug()<<"n_dll3 value is :"<<QString::number(n_dll3);
    CDll3 aa;
    aa.age =13;

    CDll3 bb;
    bb.age =15;

     qDebug()<<"aa.age value is :"<<QString::number(aa.age);
     qDebug()<<"bb.age value is :"<<QString::number(bb.age);



    // 顯示調(diào)用dll


    // QLibrary mydll("Dll3.dll"); //與exe相同目錄
    // mydll.load();
    // if(mydll.isLoaded())
    // {

    //     pAdd add = (pAdd)mydll.resolve("fnAdd");
    //     if(add)
    //     {
    //         int ret = add(1,7); //在 這里調(diào)用DLL里的函數(shù)
    //         QMessageBox::information(this,"value","get_value is: "+QString::number(ret));
    //         cout<< ret << endl ;
    //     }
    //      add = (pAdd)mydll.resolve("fnSub");
    //     if(add)
    //     {
    //         int ret = add(9,7); //在 這里調(diào)用DLL里的函數(shù)
    //         QMessageBox::information(this,"value","get_value is: "+QString::number(ret));
    //         cout<< ret << endl ;
    //     }
    //     mydll.unload();
    // }





}

MainWindow::~MainWindow()
{
    delete ui;
}

到此這篇關(guān)于QT調(diào)用vs2019生成的c++動態(tài)庫的方法實現(xiàn)的文章就介紹到這了,更多相關(guān)QT調(diào)用c++動態(tài)庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

临汾市| 鄂伦春自治旗| 吴旗县| 庄浪县| 社旗县| 屯门区| 永定县| 平武县| 陇西县| 宣城市| 郓城县| 白水县| 巴马| 灵璧县| 兰考县| 屯昌县| 班戈县| 马尔康县| 岫岩| 抚松县| 临江市| 承德县| 嘉义市| 雷波县| 江永县| 济南市| 重庆市| 福泉市| 新蔡县| 宜阳县| 密山市| 龙胜| 左贡县| 浦江县| 张家口市| 通河县| 定结县| 福安市| 云林县| 上林县| 南开区|