binary compatability

Posted on 2002-07-09
Last Modified: 2010-05-02
If I change a sub from a private to a public in a dll, will this screw up binary compatability?

Question by:pigface
  • 3
  • 2
  • 2
  • +1
LVL 18

Expert Comment

ID: 7141152
When you say DLL, I'm assuming that you mean a Sub within a Class within an Active-X DLL?  If so, the answer is yes.

If you change a Sub that is not part of a class (say in a bas module), then it shouldn't affect binary compatibility, but if you change a sub that is part of a class, then this will change that class's Interface.  And this is what breaks the compatibility.

Other things that will cause a break in compatibility include changing the number or type of parameters to a public class method, changing Enums defined in a Class module.
LVL 22

Expert Comment

ID: 7141154
Listening...but I don't think so.  The problem would be the other way around: change public to private.

I think the binary compatibility has to do with the interface.  As long as you don't delete or change and interface, you maintain compatability.  Adding has no effect.

Since changing from private to public should be considered an "Add" I would expect this to work.

Do you already have the dll?  It should be easy enough to try...

Author Comment

ID: 7141169
The sub is in a class module within the DLL.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 18

Accepted Solution

mdougan earned 50 total points
ID: 7141713
It's a little more complicated than we've been saying.

It's true that Adding to the public interface (so, changing a private to a public or adding a new public method) will probably not trigger VB to generate the warning message about breaking compatibility.  But I think what happens behind the scenes is that ANY change to the Interface (adds, deletes, or changes) causes a new IID (interface id) to be generated, and then the old Interface method pointers are actually forwarded to point to the new Interface vtable entries.  

The thought behind this is that by allowing calls to the old interface to be forwarded along to the same methods in the new interface, you keep from having to recompile the old applications.

Here is a pretty complete description of what is going on behind the scenes:

Now, during development, you are continually adding new methods to your components, which creates larger and large chains of forwarded interfaces in the registry.  Eventually, some registry entry will get hosed and the chain will break down.

They say that after doing the bulk of your development, go ahead and intentionally break your compatibility, so that you get all new GUIDS, have no more IID forwarding.  Then, distribute your component.  If you have it referenced in any VB program (under the Project|References menu) and are using Early binding (Dim x as New MyClass), then you will likely have to open the project, fix the reference and recompile.

If you use late binding in your applications (dim x as object    set x = CreateObject("MyDLL.MyClass"))  then you probably won't have to fix any references, and as long as you haven't deleted or changed any methods that the client was using, it should still run fine without recompiling.

LVL 22

Expert Comment

ID: 7141767
Very good description md.  I think you're probably right about the new ID and chain of links.

Expert Comment

ID: 7142102
No, binary compatibility will be retained. The problem is the COM interface will be changed and that will cause incompatibility issues.

I personally think this to be a bug in the binary compatibility check that VB does because by changing the interface you are making the control incompatibile with older exe's that may be using it.

Sorry, I just went through this a few month back and it totally made me crazy.

Author Comment

ID: 7142734
Firstly thanks to all of you for excellent suggestions.  Normally when peole post comments you normally get one or two duff ones.  But I have to say you guys know your stuff.

mdougan, special thanks for your excellent information.

LVL 18

Expert Comment

ID: 7143129
like schworak, I've had to go through this stuff until it makes you crazy.  If I can help one person get through it faster, I'm happy!  The link posted above is one of the best I've seen on the topic, I've saved a copy for later reference.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 238
passing parameter in sql procedure 9 65
using web browser with BING 40 131
TT Auto Dashboard 13 95
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question