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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Yet another class hierarchy problem...

Yet another class hierarchy problem...

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++debuggingjson
3 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.
  • V Offline
    V Offline
    vmaltsev
    wrote on last edited by
    #1

    Hello everyone, I'm still struggling with my classes hierarchy. Now, what I have is pure abstract interfaces classes and correspondent to them objects classes, which are actually hidden inside dll. API.h // Unique ID class class __declspec(dllexport/dllimport) CxID { public: // C-tor, D-tor, some other methods. static const int GetID(); private: static int iID; }; // Interfaces class IxA { virtual int GetA() = 0; }; class IxB_Only { virtual int GetB() = 0; }; class IxB: public IxA, public IxB_Only { }; extern __declspec(dllexport/dllimport) IxB *GetObject(); // Just a test function DLL.h #include "API.h" class CxA: public CxID, public IxA { public: // C-tor, D-tor, some methods. int GetA() { return 0xAA; } private: ID m_ID; }; class CxB: public CxA, public IxB_Only { // C-tor, D-tor, some methods. int GetB() { return 0xBB; } }; DLL.cpp CxB *g_pObj; BOOL APIENTRY DllMain(...) { ... case DLL_PROCESS_ATTACH: g_pObj = new CxB(); break; ... } // Just a global function to return pointer on global object created in DLL __declspec(dllexport/dllimport) IxB *GetObject() { return (IxB*)g_pObj; }; Now, in application: IxB *pObj = GetObj(); So, what I want to achive by doing that is to be able to cast B object, which is hidded in dll and not known to user, to public ifaces iB and iA. But, I have a problem. (Sorry for such long introduction) When I debug my app I see this:

    pObj
    |--[CxB]
    | |--CxA
    | | |--IxA __vfptr with good address and fuctions
    | |--IxB_Only __vfptr with good address and functions
    |--IxA __vfptr with good address and functions
    |--IxB_Only __vfptr with... 0xcdcdcdcd and error CXX0030: expression cannot be evaluated

    It's obvious when I do pObj->GetB() I get "Access violation". I have no idea what is wrong. It must work, I know it. But I can't see the flaw. Please, plase, plase, somebody, any clue? Thanks in advance.

    D 1 Reply Last reply
    0
    • V vmaltsev

      Hello everyone, I'm still struggling with my classes hierarchy. Now, what I have is pure abstract interfaces classes and correspondent to them objects classes, which are actually hidden inside dll. API.h // Unique ID class class __declspec(dllexport/dllimport) CxID { public: // C-tor, D-tor, some other methods. static const int GetID(); private: static int iID; }; // Interfaces class IxA { virtual int GetA() = 0; }; class IxB_Only { virtual int GetB() = 0; }; class IxB: public IxA, public IxB_Only { }; extern __declspec(dllexport/dllimport) IxB *GetObject(); // Just a test function DLL.h #include "API.h" class CxA: public CxID, public IxA { public: // C-tor, D-tor, some methods. int GetA() { return 0xAA; } private: ID m_ID; }; class CxB: public CxA, public IxB_Only { // C-tor, D-tor, some methods. int GetB() { return 0xBB; } }; DLL.cpp CxB *g_pObj; BOOL APIENTRY DllMain(...) { ... case DLL_PROCESS_ATTACH: g_pObj = new CxB(); break; ... } // Just a global function to return pointer on global object created in DLL __declspec(dllexport/dllimport) IxB *GetObject() { return (IxB*)g_pObj; }; Now, in application: IxB *pObj = GetObj(); So, what I want to achive by doing that is to be able to cast B object, which is hidded in dll and not known to user, to public ifaces iB and iA. But, I have a problem. (Sorry for such long introduction) When I debug my app I see this:

      pObj
      |--[CxB]
      | |--CxA
      | | |--IxA __vfptr with good address and fuctions
      | |--IxB_Only __vfptr with good address and functions
      |--IxA __vfptr with good address and functions
      |--IxB_Only __vfptr with... 0xcdcdcdcd and error CXX0030: expression cannot be evaluated

      It's obvious when I do pObj->GetB() I get "Access violation". I have no idea what is wrong. It must work, I know it. But I can't see the flaw. Please, plase, plase, somebody, any clue? Thanks in advance.

      D Offline
      D Offline
      darkbyte
      wrote on last edited by
      #2

      Is it possible that the problem lies within your constructors ?

      V 1 Reply Last reply
      0
      • D darkbyte

        Is it possible that the problem lies within your constructors ?

        V Offline
        V Offline
        vmaltsev
        wrote on last edited by
        #3

        Hail Darkbyte, No, simply because I don't have anything in C-tors except zeroing a couple of integers. Thanks for the answer though. :)

        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