#include "tstdll.h"tstDll::tstDll(){ }tstDll::~tstDll(){}void tstDll::dd(){ QWidget *k = new QWidget(0); k->show(); k->setStyleSheet("background-color:red;");}
#ifndef TSTDLL_H#define TSTDLL_H#include "tstdll_global.h"#include <QWidget> extern "C" class TSTDLL_EXPORT tstDll{public: tstDll(); ~tstDll(); void dd();private:};#endif // TSTDLL_H
#include "tstdllload.h"tstDllLoad::tstDllLoad(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags){ ui.setupUi(this); myLib.setFileName("tstDll"); bool b = myLib.load(); typedef tstDll (*dd)(); dd myFunction = (dd) myLib.resolve("tstDll"); if (myFunction) myFunction();}tstDllLoad::~tstDllLoad(){}
#ifndef TSTDLLLOAD_H#define TSTDLLLOAD_H#include <QtGui/QWidget>#include "ui_tstdllload.h"#include <QLibrary>class tstDllLoad : public QWidget{ Q_OBJECTpublic: tstDllLoad(QWidget *parent = 0, Qt::WFlags flags = 0); ~tstDllLoad();private: Ui::tstDllLoadClass ui; QLibrary myLib;};#endif // TSTDLLLOAD_H
C++ (Qt) myLib.setFileName("tstDll"); bool b = myLib.load(); typedef tstDll (*dd)(); dd myFunction = (dd) myLib.resolve("tstDll"); if (myFunction) myFunction();
C++ (Qt)void* QLibrary::resolve (const char *symbol)
C++ (Qt)void* getMyClass(int param);
C++ (Qt)while(!asleep()) sheep++;
void * func = <какая то функция>// а далее надо получить тип класса, допустим "tstDll", но его то я незнаю. Откуда его взять?<???>tstDll</???> * funcDll = *func;
#ifndef DLL_H#define DLL_H#include <QObject>#ifdef Q_WS_WIN #define MY_EXPORT __declspec(dllexport) #else #define MY_EXPORT #endifextern "C" MY_EXPORT QObject *getObj();#endif // DLL_H
#include "dll.h"#include <QDebug>QObject *getObj(){QObject *obj = new QObject();obj->setObjectName("tra-ta-ta");qDebug() << "OK from DLL" << endl;return obj;}
#include <QtCore/QCoreApplication>#include <QLibrary>#include <QDebug>int main(int argc, char *argv[]){QCoreApplication a(argc, argv);QLibrary lib("filname.dll");typedef QObject* (*MyPrototype)();MyPrototype myFunction = (MyPrototype)lib.resolve("getObj");if(myFunction) { QObject *obj = myFunction(); qDebug() << obj->objectName() << endl;}return a.exec();}
C++ (Qt)// export ф-ция MyLib.dll int * GetData( void ){ static int data; return &data;}