Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleRecompile an ActiveX DLL without recompiling the main application that uses it
Keywordsrecompile, ActiveX, DLL, compatible
CategoriesActiveX
 
Start a new ActiveX DLL project. Select the Project menu's Properties command. On the General tab, give the DLL a name and description. Make it a good description because you'll need to look for it later.

Create a class and give it the properties and methods you want to expose to the main program.

Compile the DLL using the File menu's Make command.

Select the Project menu's Properties command again. On the component tab, select the Binary Compatibility option and select the DLL in the text box below.

The following code shows how the sample DLL's CalculatorClass implements a public DoCalculation function.

 
Public Function DoCalculation(ByVal A As Single, ByVal B As _
    Single) As Single
    DoCalculation = A * B
End Function
 
Now start a new EXE project. Select the Project menu's References command. Find the ActiveX DLL's entry in the list. It will be listed using the description you gave it in the previous steps. Check the box next to the DLL and click OK.

Now create an instance of the class defined by the DLL and use its methods. The following code shows how the sample application creates an instance of the CalculatorClass and invokes its DoCalculation method.

 
Private Sub cmdGo_Click()
Dim calc As New CalculatorClass

    lblResult.Caption = calc.DoCalculation( _
        CSng(txtA.Text), CSng(txtB.Text))
End Sub
 
Now start a new EXE project. Select the Project menu's References command. Find the ActiveX DLL's entry in the list. It will be listed using the description you gave it in the previous steps. Check the box next to the DLL and click OK.

Now create an instance of the class defined by the DLL and use its methods. The following code shows how the sample application creates an instance of the CalculatorClass and invokes its DoCalculation method. Test the program and then compile it into an EXE file.

 
Private Sub cmdGo_Click()
Dim calc As New CalculatorClass

    lblResult.Caption = calc.DoCalculation( _
        CSng(txtA.Text), CSng(txtB.Text))
End Sub
 
Now here comes the fun part. If you open the DLL project, modify the code without removing or modifying the DLL's methods, and recompile the DLL, the executable program will still run and will use the DLL's new code.

For example, if you change the * to + in the DoCalculation function, the main program will still run. If you enter the numbers 4 and 5, the original version of the DLL returns 4 * 5 = 20. The new version returns 4 + 5 = 9. The main program will display the new result without knowing how the value is calculated.

Note that you must not change the DLL's public interface. You cannot remove or modify the declarations of any public functions, subroutines, variables, properties, etc. You can add new public properties, functions, and methods without breaking backwards compatibility. Later you will not be able to remove them, however.

If you break compatibility, you'll get an error when the main program tries to use the DLL's methods. If you try to remove a method from the DLL and then recompile it, Visual Basic will warn you that you are breaking compatibility. You'll need to remove compatibility, rebuild the DLL, then open the main program, set a reference to the new DLL, and recompile it.


Dominic Olivastro uncovered this update:

For the record this is what MS says about the problem in Q166470.

Resolution
To work around this problem, copy the ActiveX executable or DLL to a separate directory. Set binary compatibility to the copied file, and compile to the original directory. This procedure is described in Microsoft Visual Basic Books Online.

Status
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

More Information
While this behavior is not always encountered when compiling, you should follow the procedures in the RESOLUTION section above in all projects where you set binary compatibility.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated