Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
O

ochoteau

@ochoteau
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Loosing interfaces function in Single Instance Application with a Class having multiple heritance
    O ochoteau

    Hi all, How to create an Application which have a singleton class which herit form 3 other interface class (so with pure virtual functions), without loosing reference to these interface functions ? My problem is that I am lossing reference to vftable(__vfptr) between instances, so I cannot access to my interfaces in another instance of the application. More about this problem : 1 - I launch "MyClass.exe start" => OK "MyClass.exe" is running ... 2 - I launch "MyClass.exe configure" => access violation is raised, because can't access to MyClass->Configure(). NB: this problem not occur if I make -2- then -1- And although I call Configure() inside Start() it's working well. My implementation code is : #include "MyClass.h" #pragma data_seg("MyShared") MyClass* MyClass::m_instance = 0; // The MyClassUnique instance #pragma data_seg() #pragma comment(linker, "/section:MyShared,rws") int main(int argc, char *argv[]) { // Retrieve the MyClassUnique instance MyClass* Me= MyClass::Instance(); if(argc==2) { if(strcmp(argv[1],"start")==0) { MyClass->Start(); // OK MEMBER FUNCTION return 1; } if(strcmp(argv[1],"stop")==0) { C3STrace(C3S_TRACE_DEBUG, C3S_TRACE_INFO, "MAILNOTIFIER_STOP"); MyClass->Stop(); // OK MEMBER FUNCTION return 2; } if(strcmp(argv[1],"configure")==0) { MyClass->Configure(); // KO WHEN CALLED IN ANOTHER INSTANCE // Configure is one of the virtual function of one interface // I have an excetion acess violation at 0xXXXXXX reading 0xYYYYYY return 3; } } return 0; } ------------------------------------- class MyClass: public Interface1, public Interface2, public Interface3 { .... static MyClass m_instance; static MyClass* Instance(); virtual void Configure(); } ------------------------------------- MyClass* MyClass::Instance() { if( m_instance == NULL ) m_instance = new MyClass(); return m_instance; } -------------------------------------- void MyClass::Configure() { // do configuration job } -------------------------------------- Regards, Olivier.

    C / C++ / MFC help tutorial question career workspace
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups