5

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?

Jesse
  • 8,035
  • 7
  • 42
  • 56
sam
  • 53
  • 3

1 Answers1

2

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.

Community
  • 1
  • 1
Mark Ransom
  • 271,357
  • 39
  • 345
  • 578
  • Since he seems to be using classes, another instance that may cause subtle breakage, in addition to your comment about location, is if new member variables are added inside a class that resides in the DLL. – Nik Bougalis Feb 22 '13 at 18:31
  • @NikBougalis, thanks for the reminder - I've added to my answer to cover that situation. – Mark Ransom Feb 22 '13 at 18:48
  • Thanks to all for your help. – sam Feb 25 '13 at 07:33