int var = 1;
static int var = 1;
дин. дллку
// static lib...
// dll...
// exe...
// static dll/////////////////////////////////////////////////////static.h///////////////////////////////////////////////////#ifndef STATIC_H#define STATIC_H#include <QObject>class Q_DECL_EXPORT MyClass {public: MyClass(); ~MyClass();public: static MyClass* self;};class dyn_interface{public: virtual MyClass** pself() = 0;};#endif // STATIC_H///////////////////////////////////////////////////static.cpp///////////////////////////////////////////////////#include "static.h"MyClass* MyClass::self = (MyClass*) 0xabcdef;MyClass::MyClass(){ self = this;}MyClass::~MyClass(){ self = 0;}
// dynamic dll///////////////////////////////////////////////////dynamic.h///////////////////////////////////////////////////#ifndef DYNAMIC_H#define DYNAMIC_H#include <QObject>#include "static.h"class dynamic : public dyn_interface{public: dynamic(); ~dynamic();public: MyClass** pself();};#endif // DYNAMIC_H///////////////////////////////////////////////////dynamic.cpp///////////////////////////////////////////////////#include "dynamic.h"dynamic::dynamic(){}dynamic::~dynamic(){ }MyClass** dynamic::pself(){ return &MyClass::self;}extern "C" Q_DECL_EXPORT dynamic* createObject(){ return new dynamic;}
///////////////////////////////////////////////////main.cpp///////////////////////////////////////////////////#include <QtGui>#include <static.h>int main(int argc, char *argv[]){ QApplication a(argc, argv); MyClass* stat_obj = new MyClass; QTextBrowser browser; typedef dyn_interface* (*proto)(); QLibrary lib("dynamic"); proto func = (proto) lib.resolve("createObject"); dyn_interface* obj = func(); MyClass** pSelf = obj->pself(); QString text; text = QString( "in exe:<br>&MyClass::self=%1<br>MyClass::self=%2<br><br>" "in dll pself:<br>&MyClass::self=%3<br>MyClass::self=%4<br><br>") .arg((quint32)&MyClass::self,8,16) .arg((quint32)MyClass::self,8,16) .arg((quint32)pSelf,8,16) .arg((quint32)*pSelf,8,16); browser.insertHtml(text); browser.show(); return a.exec();}