Click here to Skip to main content
15,921,531 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Task Manager Pin
Michael P Butler30-Jul-04 4:36
Michael P Butler30-Jul-04 4:36 
GeneralRe: Task Manager Pin
Jnewg530-Jul-04 5:07
Jnewg530-Jul-04 5:07 
GeneralRe: Task Manager Pin
Michael P Butler30-Jul-04 6:29
Michael P Butler30-Jul-04 6:29 
GeneralRe: Task Manager Pin
jmkhael30-Jul-04 6:33
jmkhael30-Jul-04 6:33 
GeneralRe: Task Manager Pin
Michael P Butler30-Jul-04 6:36
Michael P Butler30-Jul-04 6:36 
GeneralRe: Task Manager Pin
jmkhael30-Jul-04 6:40
jmkhael30-Jul-04 6:40 
GeneralCRecordset open table Pin
sirtimid30-Jul-04 3:39
sirtimid30-Jul-04 3:39 
GeneralYet another class hierarchy problem... Pin
vmaltsev30-Jul-04 3:22
vmaltsev30-Jul-04 3:22 
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
<br />
// Unique ID class<br />
class __declspec(dllexport/dllimport) CxID {<br />
public:<br />
  // C-tor, D-tor, some other methods.<br />
  static const int GetID();<br />
private:<br />
  static int iID;<br />
};<br />
// Interfaces<br />
class IxA {<br />
  virtual int GetA() = 0;<br />
};<br />
class IxB_Only {<br />
  virtual int GetB() = 0;<br />
};<br />
class IxB: public IxA, public IxB_Only {<br />
};<br />
<br />
extern __declspec(dllexport/dllimport) IxB *GetObject(); // Just a test function<br />

DLL.h
<br />
#include "API.h"<br />
class CxA: public CxID, public IxA {<br />
public:<br />
  // C-tor, D-tor, some methods.<br />
  int GetA() { return 0xAA; }<br />
private:<br />
  ID m_ID;<br />
};<br />
class CxB: public CxA, public IxB_Only {<br />
  // C-tor, D-tor, some methods.<br />
  int GetB() { return 0xBB; }<br />
};<br />

DLL.cpp
<br />
CxB *g_pObj;<br />
BOOL APIENTRY DllMain(...) {<br />
   ...<br />
   case DLL_PROCESS_ATTACH:<br />
     g_pObj = new CxB();<br />
   break;<br />
   ...<br />
}<br />
<br />
// Just a global function to return pointer on global object created in DLL<br />
__declspec(dllexport/dllimport) IxB *GetObject() {<br />
  return (IxB*)g_pObj;<br />
};<br />

Now, in application:
<br />
IxB *pObj = GetObj();<br />

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.
GeneralRe: Yet another class hierarchy problem... Pin
darkbyte30-Jul-04 6:17
darkbyte30-Jul-04 6:17 
GeneralRe: Yet another class hierarchy problem... Pin
vmaltsev30-Jul-04 12:27
vmaltsev30-Jul-04 12:27 
GeneralSerial Port Communication Pin
ciitpk30-Jul-04 3:05
ciitpk30-Jul-04 3:05 
GeneralRe: Serial Port Communication Pin
ThatsAlok30-Jul-04 3:26
ThatsAlok30-Jul-04 3:26 
GeneralRe: Serial Port Communication Pin
valikac30-Jul-04 5:10
valikac30-Jul-04 5:10 
Generalcapturing frame and manipulate image Pin
milos++30-Jul-04 2:29
milos++30-Jul-04 2:29 
GeneralRe: capturing frame and manipulate image Pin
normanS1-Aug-04 20:26
normanS1-Aug-04 20:26 
GeneralRe: capturing frame and manipulate image Pin
milos++2-Aug-04 3:58
milos++2-Aug-04 3:58 
GeneralNo idea Pin
normanS2-Aug-04 19:26
normanS2-Aug-04 19:26 
GeneralRe: No idea Pin
milos++2-Aug-04 23:43
milos++2-Aug-04 23:43 
GeneralPrint Preview appears microscopic Pin
JHAKAS30-Jul-04 2:28
JHAKAS30-Jul-04 2:28 
GeneralDialog Box Controls Pin
ciitpk30-Jul-04 2:25
ciitpk30-Jul-04 2:25 
GeneralRe: Dialog Box Controls Pin
Michael P Butler30-Jul-04 2:29
Michael P Butler30-Jul-04 2:29 
GeneralRe: DirectShow and Graphics Overlay Pin
Antti Keskinen30-Jul-04 2:10
Antti Keskinen30-Jul-04 2:10 
GeneralRe: DirectShow and Graphics Overlay Pin
p_smith30-Jul-04 3:33
p_smith30-Jul-04 3:33 
GeneralRe: DirectShow and Graphics Overlay Pin
Antti Keskinen30-Jul-04 10:52
Antti Keskinen30-Jul-04 10:52 
GeneralRe: DirectShow and Graphics Overlay Pin
Antti Keskinen30-Jul-04 11:45
Antti Keskinen30-Jul-04 11:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.