- INDEX VB TO NET
- HOW TO MODIFY THE WAY THE CODE IS GENERATED
- SUPPORT CLASS INSTANTIATION MODELS THROUGH HELPER
Support Class Instantiation Models through Helper
The ActiveX EXE and ActiveX DLL project types are used to allow multiple applications to share the same code. This technique saves time since it is required to write the code only once. It also allows devoting extra time to debugging the shared code.
Modifying the shared libraries becomes easier since it is necessary only to update the common DLL/EXE files and all related applications that use them will be automatically updated.
These particular project types represent a potential migration challenge since the exact functionality and technical behavior is not straight simple to obtain in the .NET platform.
The Visual Basic Upgrade Companion is able to automatically convert the class instantiation schema for these project types using a helper class in order to obtain functional equivalence on the resulting code behavior.
This optional feature enables the conversion of ActiveX DLL/EXEs (with global variables) via a helper class (ComponentClassServer) that controls the instantiation of the generated class libraries.
Remarks: ActiveX EXEs are converted to .Net out of process and the instantiation of the components is performed using helper classes. ActiveX DLLs are converted to .Net using application domains and the instantiation of the components is archived using helper classes. With this approach most of the ActiveX functionality is replicated in the converted code. |
The VBUC converts Visual Basic 6 ActiveX EXEs to .Net EXE projects (out of process) and ActiveX DLL to standard .Net assemblies (class library projects).
One of the main differences between VB6 ActiveX and .NET assemblies is the way of how the component is instantiated. This initialization determines the lifetime behavior for the component. A helper class is used to replicate the following instantiation types of the VB6 ActiveX:
- Private
- PublicNotCreatable
- SingleUse
- GlobalSingleUse
- MultiUse
- GlobalMultiUse
For example:
Source VB6
VERSION 1.0 CLASS
Attribute VB_Name = "Customer"
Public Property Let TheNumber(ByVal new_value As Integer)
g_TheNumber = new_value
End Property
Public Property Get TheNumber() As Integer
TheNumber = g_TheNumber
End Property
The following code is located in a main application that uses the ActiveX EXE.
Private m_Customer1 As ExeBillingObjects.Customer
Private m_Customer2 As ExeBillingObjects.Customer
Private Sub Form_Load()
Set m_Customer1 = New ExeBillingObjects.Customer
Set m_Customer2 = New ExeBillingObjects.Customer
End Sub
Private Sub cmdGet_Click()
txtTheNumber.Text = m_Customer1.TheNumber
End Sub
Target VB.NET
Public Class Customer Inherits UpgradeHelpers.VB6.Activex.ComponentClassHelper
Public Property TheNumber() As Integer
Get
Return g_TheNumber
End Get
Set(ByVal Value As Integer)
g_TheNumber = Value
End Set
End Property
End Class
The following code is located in a main application that uses the ActiveX EXE.
Private m_Customer1 As ExeBillingObjects.Customer
Private m_Customer2 As ExeBillingObjects.Customer
Private Sub cmdGet_Click(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles cmdGet.Click
txtTheNumber.Text = CStr(m_Customer1.TheNumber)
End Sub
Private Sub Form1_Load(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles MyBase.Load
m_Customer1 = ExeBillingObjects.ExeBillingObjectsFactory.Create(Of ExeBillingObjects.Customer)(m_Customer1)m_Customer2 = ExeBillingObjects.ExeBillingObjectsFactory.Create(Of ExeBillingObjects.Customer)(m_Customer2)
End Sub
Target C#
public class Customer : UpgradeHelpers.Activex.ComponentClassHelper
{
public int TheNumber
{
get {
return Module1.g_TheNumber;
}
set {
Module1.g_TheNumber = value;
}
}
}
The following code is located in a main application that uses the ActiveX EXE.
private ExeBillingObjects.Customer m_Customer1 = null;
private ExeBillingObjects.Customer m_Customer2 = null;
private void cmdGet_Click( Object eventSender, EventArgs eventArgs)
{
txtTheNumber.Text = Convert.ToString(m_Customer1.TheNumber);
}
private void Form1_Load( Object eventSender, EventArgs eventArgs)
{
m_Customer1 = ExeBillingObjects.ExeBillingObjectsFactory.Create <ExeBillingObjects.Customer>(m_Customer1);
m_Customer2 = ExeBillingObjects.ExeBillingObjectsFactory.Create <ExeBillingObjects.Customer>(m_Customer2);
}