1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// ------------------------------------
// Compilé dans myLib.dll
//
// Runtime : multithread (debug) DLL
// ------------------------------------
#include "myObject.h"
class MY_API Globals : public Singleton<Globals>
{
friend class Singleton<Globals>;
public:
Globals();
~Globals();
int m_nombre;
myObject* mp_object; // mis à null dans le constructeur
...
};
// ------------------------------------
// Compilé dans MyApplication.exe
// Link avec MyLib.dll
// ------------------------------------
class MyApplication
{
...
int M_init();
Object* mp_obj; // mis à 0 dans le constructeur
...
};
MyApplication::~MyApplication()
{
delete mp_obj;
}
int MyApplication::M_init()
{
// > nombre
Globals::Instance().m_nombre = 1234;
// > obj
mp_obj = new Object();
Globals::Instance().mp_object = mp_obj; // objet détruit à la fin d'éxécution de l'appli
// > chargement des plugins
// La class plugin implémente une méthode virtuelle M_init()
Plugin* myPlugin = PluginManager.M_load("MyPlugin.dll");
myPlugin.M_init();
}
// ------------------------------------
// Compilé dans MyPlugin.dll
// Linké avec MyLib.dll
// ------------------------------------
include "Object.h"
include "Globals.h"
void myPlugin::M_init()
{
-> accès à Globals::Instance().mp_object qui vaut ici 0.
} |