Qt 动态加载第三方库

最近写桌面测试程序,要使用到tsclib.dll, 只有一个TSCLib.dll和TSCLIB.lib文件。因此选择显示调用dll——使用QLibrary类

在pro文件中,添加.lib文件的位置: LIBS+= -L D:/hitempt/api/ -l myDLL

dll文件在动态调用时有两个作用:

1.编译时用到,   

2.运行时用到,

因此至少在运行文件夹中有dll文件,源码中dll文件位置与指定位置相同。

 

定义函数指针类型
typedef int (*ABOUT)();
typedef int (*OPENPORT)(char *);
 

 

 OPENPORT openport;  //定义函数指针
QLibary TSCdll;   //定义QLibary结构体
bool MainWindow::dynamicLoad(){   
    bool ret = false

 

    TSCdll.setFileName("lib/TSCLIB.dll");
    if(TSCdll.load())
    {
 
        if((openport = (OPENPORT)TSCdll.resolve("openport"))==NULL)    //返回
            qDebug()<<"can not resolved it!";
        .......

    }

   return ret;
}

 

 

 

这是C编程的库

TSCLIB 库的函数原型如下

 int CALLBACK openport(char*);
 int CALLBACK closeport();
 int CALLBACK sendcommand (char*);
 int CALLBACK setup (char *,char *,char *,char *,char *,char *,char *);
 int CALLBACK downloadpcx (char *filename,char *image_name);
 int CALLBACK barcode (char *,char *,char *,char *,char *,char *,char *,char *,char *);
 int CALLBACK printerfont (char *,char *,char *,char *,char *,char *,char *);
 int CALLBACK clearbuffer();
 int CALLBACK printlabel(char *, char *);
 int CALLBACK formfeed();
 int CALLBACK nobackfeed();
 BOOL CALLBACK isready();
 int CALLBACK windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, char *szFaceName, char *content);

 int CALLBACK about();

/****************************************************************************************/

这样在定义函数执行时就有的放矢。

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值