标题:QT如何调用外部DLL中的类中的函数?
作者:woshigaowei5
日期:2019-08-13 18:14
内容:
我现在只有一个外部dll文件**Protocol.dll**,想用QT调用里面的函数,没有.h和.lib。
在网上找了许多方法都不行。
厂家只给了一个**C#**的例程,程序如下:
Protocol.Ax1485 ax1485 = new Protocol.Ax1485();ax1485.OpenPort()其中**Ax1485**是一个类,**OpenPort()**是该类中的一个函数,我现在想用QT调用这个函数。我现在是这么做的:
typedef int (*Fun)();QLibrary testLib("Protocol.dll"); //已经把dll放在debug中if (testLib.load()){Fun getObj = (Fun)testLib.resolve("OpenPort");if (getObj){qDebug()
#1 [toby520 08-13 18:50]
class TestInterface
{
public:
virtual ~TestInterface()
{
}
virtual int getValues() = 0;
}
class TESTDLL_LIBSHARED_EXPORT TestDLL_lib : public TestInterface
{
public:
TestDLL_lib();
virtual ~TestDLL_lib();
int a;
int b;
int c;
int getValues() override; // MSVC may not support "override"
};
// return pointer to interface!
// TestDLL_lib can and should be completely hidden from the application
extern "C" TESTDLL_LIBSHARED_EXPORT TestInterface *create_TestDLL_lib()
{
return new TestDLL_lib();
}
#2 [fsu0413 08-13 22:37]
这个DLL是.net的
#3 回 fsu0413 的帖子 [woshigaowei5 08-14 08:27]
fsu0413:这个DLL是.net的
(2019-08-13 22:37)
.net的 QT不能调用吗?
#4 回 toby520 的帖子 [woshigaowei5 08-14 08:35]
toby520:class TestInterface
{
public:
virtual ~TestInterface()
{
....... (2019-08-13 18:50)
没太看懂,能详细说下嘛?
#5 [cj123sn 08-14 08:52]
.net的dll需要转换一道,百度有方法