45.QT-连接外部DLL,解决调用resolve失败原因

查看MZ_Card.dll对应的文档手册,如下图所示:

所以代码写为:

typedef BOOL (*Fun)(BOOL IsOpenComm,unsigned long Port,  unsigned long nBaud, unsigned int BeepCnt); //定义函数指针 
void func()
{
    
       Fun open=(Fun)mylib.resolve("MZ_Card.dll","SendBeep");    //援引函数
       if (open)                  //是否成功连接上函数
       {
                 qDebug()<<"Link to Function is OK!";
                 qDebug()<<open(true,19,38400,2);      //这里函数指针调用dll中的SendBeep函数
       }
       else
                 qDebug()<<"Linke to Function is not OK!!!!";
}

运行打印,发现调用resolve失败:

难道是函数名出错了?

用记事本打开MZ_Card.dll,搜索SendBeep关键字,找到如下图所示:

显然确实和文档给的不一样,有可能是不同编译器的差异吧.所以修改代码:

Fun open=(Fun)mylib.resolve("MZ_Card.dll","_SendBeep@16");

运行后OK:

 

 

猜你喜欢

转载自www.cnblogs.com/lifexy/p/10954438.html