0

In my case I write a Kernel.dll which wraps CxImage object(either CxImageJPG or CxImage) defined in xImage.dll which shared with other binary modules(no sourcecode):

class CCxImageWraper{
  public:
    shared_ptr<CxImage> m_spImage;
    ...
}

when I use a dynamic_cast it fails with std::__non_rtti_object exception:

m_spImage.reset(new CxImageJPG);  // always std::__non_rtti_object exception
CxImageJPG* cxJpgImage = dynamic_cast<CxImageJPG*>(m_spImage.get());

I'm sure that kernal.dll project use the option /GR (Enable Run-Time Type Information), and the pointer m_spImage.get() here is not NULL and it is surely point to a CxImageJPG instatance. Don't know why it throws std::__non_rtti_object Is any information I was missing?

I did try create a new console project Test.exe and TestDll.dll, Test.exe always turn on GR switch, TestDll.dll has two class: BaseClass, SubClass, whatever option I set to TestDll.dll: /GR or /GR-, /MT or /MDd or /MTd. Test.exe always can dynamic_cast the object defined in TestDll.dll:

boost::shared_ptr<BaseClass> spItem(new SubClass());
SubClass* pClass = dynamic_cast<SubClass*>(spItem.get());  // always no exception

Aready checked problem, but can't find more information to my problem:

Community
  • 1
  • 1
Gohan
  • 2,422
  • 2
  • 26
  • 45
  • If you don't have the source code for the dll that implements `CxImageJPG`, why do you think it has been compiled with RTTI? – Roger Rowland Jul 29 '14 at 12:05
  • @rogerrowland I didn't assume that it compiled with RTTI, which I don't know, I just build a dll, compiled without RTTI, and the class in the dll can be dynamic_cast, I don't know why – Gohan Jul 29 '14 at 12:16

0 Answers0