Yet another class hierarchy problem...
-
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.cppCxB *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 evaluatedIt'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.
-
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.cppCxB *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 evaluatedIt'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.