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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Loosing interfaces function in Single Instance Application with a Class having multiple heritance

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

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestioncareerworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ochoteau
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • 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.

      M Offline
      M Offline
      Member 754960
      wrote on last edited by
      #2

      Does this compile?

      class MyClass
      {
      static MyClass m_instance;
      }

      MyClass* MyClass::m_instance = 0; // different types here

      and this

      MyClass->Start(); // MyClass as a pointer????

      I'm also doubtful about the use of shared data segment memory as an interprocess mechanism.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

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