c++ - Segfault when calling a virtual function in another DLL -


i have two-part program main core needs have adapter registered , call register. parts in separate dlls, , core doesn't know adapter's specifics (besides methods , parameters ahead of time). i've tried setting following code , recieve segfault every time core tries call adapter method:

core.hpp/cpp (combined , simplified):

class core { public:     core()         : madapter(null)     { }      void dostuff(int param)     {         if ( this->madapter )         {             this->madapter->prepare(param);         }     }      void register(adapter * adapter)     {         this->madapter = adapter;     }  private:     adapter * madapter; }; 

adapter.hpp/cpp (in core library):

class adapter { public:     adapter(core * core) { }      virtual void prepare(int param)     {         // testing, defined here         throw("non-overridden adapter function called.");     } }; 

adapterspecific.hpp/cpp (second library):

class adapter_specific     : adapter { public:     adapter_specific(core * core)     {         core->register(this);     }      void prepare(int param) { ... } }; 

all classes , methods marked dll export while building first module (core) , core marked export, adapter import while building adapter.

the code runs fine until point core::dostuff called. walking through assembly, appears resolves function vftable, address ends 0x0013nnnn, , modules in 0x0084nnnn , above range. visual studio's source debugger , intellisense shows the entries in vftable same , appropriate 1 go low address (one goes 0xf-something, seems equally odd).

edit clarity: execution never re-enters adapter_specific class or module. supposed address call invalid , execution gets lost there, resulting in segfault. it's not issue code in adapter class, why left out.

i've rebuilt both libraries more once, in debug mode. pure c++, nothing fancy. i'm not sure why won't work, need call other class , rather avoid using struct of function ptrs.

is there way use neat callbacks between modules or somehow impossible?

you said methods declared dll exports. methods (member functions) not have marked way ,exporting class sufficient. don't know if it's harmfull if do.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -