Overriding classes / functions from .dll

Let's say I have class A and class B. Inherits from class A and implements several virtual functions. The only problem is that B is defined in the DLL. Right now I have a function that returns an instance of class A, but it extracts it from a static function in .dll that returns an instance of class B. My plan is to call the created object and hopefully have the functions in .dll executed instead of functions defined in class A. For some reason, I keep getting memory access restrictions. Is there something that I don’t understand that this plan will not work?

+3
source share
3 answers

C ++ classes do not cross DLL boundaries very well. DLLs and EXEs must be built using the same compiler and version — preferably together. This is due to the fact that features of the class implementation, such as vtbllayout / order, as well as implementations of some standard library functions (i.e. std::string), are not portable. Various compiler compilation schemes also cannot be used for compilers / versions. The only interface that you can reliably expose outside the boundaries of the DLL is the C interface.

Since I do not know the exact scenario, I cannot be sure, but you are probably referring to some type of undefined behavior on the border of the DLL.

EDIT: it is also possible that at some point the DLL unloaded, which led to the call of nonexistent code in B.

+1

. - ? () ++

+1

Visual Studio?

win32, "" → "" Win32 exceptions Thrown
exe, F5. , .

0

Source: https://habr.com/ru/post/1739809/


All Articles