2015-06-17 17:44 GMT+02:00 Etienne Sandré-Chardonnal <[email protected] >:
> Dear all, > > I have a plugin system in my app based on interfaces (classes with only > pure virtual functions). The app is compiled with mingw-w64 4.9.2 and works > well with plugin dlls compiled with the same compiler. > > Now I am trying to support MSVC compiled plugins. > > This works partially : the app can call the methods from interface objects > provided by the DLL. However, if I pass a pointer on an interface class to > one of the DLL methods, it does a segmentation fault. > > After debugging, I have seen this: > > *A is a pointer to an object deriving from InterfaceA , and created by the > app. > *B is a pointer to an object deriving from InterfaceB, and created by the > dll > > From the app, I call B->someMethod(A); > and someMethod calls A->someOtherMethod() > > When I debug inside someOtherMethod (which is an app side method), "this" > should point on *A, but it points on *B. Which causes the segmentation > fault afterwards. > > Can this be an ABI issue? > This is most likely an ABI issue yes, because you are relying on the binary interface of the app and dll to be the same (i.e. the objects are assumed to have the same memory layout and alignment and padding and whatnot). Unfortunately, different compilers generate different class layout and contents (think vptr) so they can be incompatible. A way to solve this is to have only a C-style interface (no class types as parameters) and have the plugin handle all the class creation and memory management so that the "user code" only sees an opaque pointer (void*) to something the plugin created and manages the memory for. This requires quite some changes in the code most likely, but I don't know of another way to work around this incompatibility. Maybe someone else here has another idea :) Cheers, Ruben
------------------------------------------------------------------------------
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
