Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recompiling MFC Extension DLL changes entry points of exported functions

Tags:

c++

dll

mfc

I have an MFC Extension DLL which exports a C++ class, and I need to modify the behavior of a class method. The changes don’t affect the signature of methods of the class.

I don't want to recompile the modules that used the "lib" file of the previously released version of this library.

What happens if the changes modify the entry points address of the functions?

For example, the address of the constructor changed:

Export   Ordinal      Function    Hint                      Entry Point
[+  ]    3 (0x0003)   2 (0x0002)  ??0CLangManager@@QAE@XZ   0x00009CB0    (OLD DLL)
[+  ]    3 (0x0003)   2 (0x0002)  ??0CLangManager@@QAE@XZ   0x00009760    (NEW DLL)

Should I recompile the modules that use the library anyway?

I tested the recompiled library - with new entry points - using the released executables and everything works fine. I'm not sure that this scenario is hiding some side-effects.

When is it necessary to recompile an executable linking to a DLL?

When does the binary compatibility get broken?

like image 272
sam Avatar asked Nov 04 '22 04:11

sam


1 Answers

This is one of the benefits of using a DLL - you can change it, and as long as you continue to keep the same function signatures everything will work fine. Linking occurs as the program is loaded, so a change of address doesn't make any difference.

You will want to be absolutely positive that any classes defined in the DLL don't have any inline methods, since those may not work with any internal changes to the object.

Binary compatibility is broken when a function signature changes, or when a public member variable changes location within the object. I would avoid public member variables in a DLL altogether.

Edit: as noted in the comments, you can also get into trouble if variables are added to or removed from the class, changing its size. This becomes a problem if objects are created outside of the DLL, either as local variables or via new. You can avoid this by creating all your object instances from inside the DLL and passing pointers to the caller. You can also avoid problems by using the PIMPL idiom on your classes.

like image 114
Mark Ransom Avatar answered Nov 09 '22 15:11

Mark Ransom