абстрактный класс
C++ (Qt)
class WindowInterface
{
public:
virtual void show() = 0;
virtual int exec() = 0;
virtual void print() = 0;
};
dll
C++ (Qt)
#include "global.h"
#include <QDialog>
#include <QList>
#include <iostream>
#include "windowinterface.h"
namespace Ui {
class Editor;
}
class SHARED_EXPORT Editor :
public QDialog,
public WindowInterface
{
Q_OBJECT
public:
explicit Editor(QWidget *parent = 0);
~Editor();
void print()
{
QList<int> l;
l << 1 << 2;
cout << "Test " << l.size() << endl;
}
virtual void show()
{
QDialog::show();
}
virtual int exec()
{
return QDialog::exec();
}
private:
Ui::Editor *ui;
};
C++ (Qt)
#include "editor.h"
#include "ui_editor.h"
extern "C" WindowInterface* SHARED_EXPORT createInterface()
{
int argc = 0;
char **argv = 0;
if(QApplication::instance() == 0)
new QApplication(argc, argv);
return new Editor;
}
Editor::Editor(QWidget *parent) :
QDialog(parent),
ui(new Ui::tEditor)
{
ui->setupUi(this);
}
Editor::~Editor()
{
delete ui;
}
exe Visual Studio 2010
C++ (Qt)
#include "windowinterface.h"
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
typedef WindowInterface* (*WindowInterfaceFunc)();
HINSTANCE hDll = NULL;
hDll = LoadLibrary(TEXT(".\\editor.dll"));
if(hDll == NULL)
return -1;
WindowInterfaceFunc f = (WindowInterfaceFunc) GetProcAddress(hDll, "createInterface");
if(f == NULL)
return -2;
WindowInterface *window = f();
window->print();
window->show();
window->exec();
return 0;
}
А, да, забыл. dll делается в QtCreator'е с mingw