Groups | Blog | Home
all groups > vb.net upgrade > april 2005 >

vb.net upgrade : Convert forms using Ocx to use there .NET framework version


jacqueline.azim-roman
4/13/2005 12:21:11 PM
I am trying to port a big VB6 application : near 100 modules (ActiveX DLL)
hosting more than 500 VB Forms and 200 CrystalReport Reports.

We have writed 16 VB6 user controls hosted in an OCX dll and we want to
convert them to .NET.

Port of this controls to VB.NET is not a problem but convert our 500 VB6
Forms to use the new .NET User Controls is one : With Visual Studio 2003 VB6
Upgrade tools, ported forms using OCX continue to use wrapped VB6 OCX and
the OCX control properties are stored in .ResX file in a control.OcxState
resource.

Does someone know a tool or method to remplace automaticaly the OcxState
property by its contained readable properties in source code or some
alternative methods to stop using OCX controls in our project.

Our 2 objectives are : making version upgrade easier (no need to register
new version of our OCX controls) and have the ability to use full new .NET
capabilities.

Thanks

Renaud Bancel
4/13/2005 12:38:36 PM
Sorry i worte this message after registering one of my fiends to a Web
Access Provider and the registration process changed my identity in my
newsgroup reader. I am Renaud Bancel (and not Jacquelin Azim-Roman) :

I am trying to port a big VB6 application : near 100 modules (ActiveX DLL)
hosting more than 500 VB Forms and 200 CrystalReport Reports.

We have writed 16 VB6 user controls hosted in an OCX dll and we want to
convert them to .NET.

Port of this controls to VB.NET is not a problem but convert our 500 VB6
Forms to use the new .NET User Controls is one : With Visual Studio 2003 VB6
Upgrade tools, ported forms using OCX continue to use wrapped VB6 OCX and
the OCX control properties are stored in .ResX file in a control.OcxState
resource.

Does someone know a tool or method to remplace automaticaly the OcxState
property by its contained readable properties in source code or some
alternative methods to stop using OCX controls in our project.

Our 2 objectives are : making version upgrade easier (no need to register
new version of our OCX controls) and have the ability to use full new .NET
capabilities.

Thanks


Oscar Calvo
4/15/2005 4:49:46 PM
Hello Renaud, I feel your pain.=20

Here is some pseudo code that will read the data from the OcxState =
property and convert it to properties.

Dim bag As Hashtable

=20

Overridable Sub BeginInit() Implements ISupportInitialize.BeginInit

=20

End Sub

=20

Overridable Sub EndInit() Implements ISupportInitialize.EndInit

If bag Is Nothing Then

Return

End If

Dim properties As PropertyDescriptorCollection =3D =
TypeDescriptor.GetProperties(Me)

For Each key As Object In bag.Keys

Dim prop As PropertyDescriptor =3D properties.Item(key)

If Not prop Is Nothing Then

Try

prop.SetValue(Me, bag.Item(key))

Catch

End Try

End If

Next

End Sub

=20

<RefreshProperties(RefreshProperties.All), _

Browsable(False), _

EditorBrowsable(EditorBrowsableState.Advanced)> _

Public Property OcxState() As System.Windows.Forms.AxHost.State

Get

Return Nothing

End Get

Set(ByVal state As System.Windows.Forms.AxHost.State)

Dim stateType As Type =3D =
GetType(System.Windows.Forms.AxHost.State)

Dim bindingFlags As BindingFlags =3D bindingFlags.GetField + =
bindingFlags.Instance + bindingFlags.NonPublic

Dim propBag As Object =3D stateType.InvokeMember("propBag", =
bindingFlags, Nothing, state, Nothing)

If propBag Is Nothing Then

Dim buffer As Byte() =3D =
stateType.InvokeMember("buffer", bindingFlags, Nothing, state, Nothing)

Dim stream As MemoryStream =3D New MemoryStream(buffer)

Dim formatter As =
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter =3D New =
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter

Try

bag =3D CType(formatter.Deserialize(stream), =
Hashtable)

Catch

bag =3D New Hashtable

End Try

Else

bag =3D propBag.GetType().InvokeMember("bag", =
bindingFlags, Nothing, propBag, Nothing)

End If

End Set

End Property



You should insert this code into your UserControl or create a new base =
class for all of your constrols.=20

For better compatibility, the UserControl should implement the interface =
ISupportInitialize.=20

Your migrated forms will be able to load the property settings stored in =
the OcxState, if you save the forms then the properties will be stored =
in the InitializeComponent using your control setter properties.

Later on I recommend that you remove this code from your production =
code, or encloded with #if / #endif.

I am very interested in your results, please keep us posted.In =
particular, I would like to know what kind of complex types are you =
storing in your UserControls.=20

I am developing a set of helper classes to help people with migration =
problems, this is one area of interest.



Regarding your second objective, can you elaborate a little more? Are =
talking about making your .NET version of the controls binary compatible =
with your VB6 Clients?=20



Enjoy,



Oscar Calvo

ArtinSoft http://www.artinsoft.com

The Software Migration Specialist



[quoted text, click to view]
Oscar Calvo
4/15/2005 5:18:47 PM
I bloged this at http://spaces.msn.com/members/oscarcalvo/

[quoted text, click to view]
Hello Renaud, I feel your pain.=20

Here is some pseudo code that will read the data from the OcxState =
property and convert it to properties.

Dim bag As Hashtable

=20

Overridable Sub BeginInit() Implements =
ISupportInitialize.BeginInit

=20

End Sub

=20

Overridable Sub EndInit() Implements ISupportInitialize.EndInit

If bag Is Nothing Then

Return

End If

Dim properties As PropertyDescriptorCollection =3D =
TypeDescriptor.GetProperties(Me)

For Each key As Object In bag.Keys

Dim prop As PropertyDescriptor =3D properties.Item(key)

If Not prop Is Nothing Then

Try

prop.SetValue(Me, bag.Item(key))

Catch

End Try

End If

Next

End Sub

=20

<RefreshProperties(RefreshProperties.All), _

Browsable(False), _

EditorBrowsable(EditorBrowsableState.Advanced)> _

Public Property OcxState() As System.Windows.Forms.AxHost.State

Get

Return Nothing

End Get

Set(ByVal state As System.Windows.Forms.AxHost.State)

Dim stateType As Type =3D =
GetType(System.Windows.Forms.AxHost.State)

Dim bindingFlags As BindingFlags =3D bindingFlags.GetField =
+ bindingFlags.Instance + bindingFlags.NonPublic

Dim propBag As Object =3D =
stateType.InvokeMember("propBag", bindingFlags, Nothing, state, Nothing)

If propBag Is Nothing Then

Dim buffer As Byte() =3D =
stateType.InvokeMember("buffer", bindingFlags, Nothing, state, Nothing)

Dim stream As MemoryStream =3D New =
MemoryStream(buffer)

Dim formatter As =
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter =3D New =
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter

Try

bag =3D CType(formatter.Deserialize(stream), =
Hashtable)

Catch

bag =3D New Hashtable

End Try

Else

bag =3D propBag.GetType().InvokeMember("bag", =
bindingFlags, Nothing, propBag, Nothing)

End If

End Set

End Property

=20

You should insert this code into your UserControl or create a new base =
class for all of your constrols.=20

For better compatibility, the UserControl should implement the =
interface ISupportInitialize.=20

Your migrated forms will be able to load the property settings stored =
in the OcxState, if you save the forms then the properties will be =
stored in the InitializeComponent using your control setter properties.

Later on I recommend that you remove this code from your production =
code, or encloded with #if / #endif.

I am very interested in your results, please keep us posted.In =
particular, I would like to know what kind of complex types are you =
storing in your UserControls.=20

I am developing a set of helper classes to help people with migration =
problems, this is one area of interest.

=20

Regarding your second objective, can you elaborate a little more? Are =
talking about making your .NET version of the controls binary compatible =
with your VB6 Clients?=20

=20

Enjoy,

=20

Oscar Calvo

ArtinSoft http://www.artinsoft.com

The Software Migration Specialist



[quoted text, click to view]
AddThis Social Bookmark Button