Solved

binary compatability

Posted on 2002-07-09
8
227 Views
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?

Cheers.
0
Comment
Question by:pigface
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 18

Expert Comment

by:mdougan
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.
0
 
LVL 22

Expert Comment

by:rspahitz
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...
0
 

Author Comment

by:pigface
ID: 7141169
The sub is in a class module within the DLL.
0
 
LVL 18

Accepted Solution

by:
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:

http://www.microsoft.com/MSJ/0100/versioning/versioning.asp

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.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

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

Expert Comment

by:schworak
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.
0
 

Author Comment

by:pigface
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.

Thanks.
0
 
LVL 18

Expert Comment

by:mdougan
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Public Sub, Empty Cell 7 57
VBA to format 3 79
bit defender blocks good applications 2 52
message box in access 4 33
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now