Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Suppose your VB6 has this:

Code Block
languagevb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SysInfo control on a Form
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>1301    Begin SysInfoLib.SysInfo SysInfo1 
 1302       Left            =   13920
 1303       Top             =   0
 1304       _ExtentX        =   1005
 1305       _ExtentY        =   1005
 1306       _Version        =   393216
 1307    End
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Logic to use SysInfo control to get ScrollBarSizwe
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 8014 Private Function XSizePartsUpDown()
...
>8020         .Width = SysInfo1.ScrollBarSize
...
 8024     End With
 8025 End Function

...

We wish to change a control instance property declared in a COM interface description file (IDF) to a static readonly property declared in a .NET framework class.

Code Block
languagec#
Here is the property in the COM IDF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
proj\idf\FromIdl\SYSINFO.OCX.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17    <class id="ISysInfo" parent="IDispatch">
...
>  26       <property id="ScrollBarSize" type="Single" status="Out"/>
...
   32    </class>

And, here is the replacement property in WinForms:

      //
      // Summary:
      //     Gets the default width, in pixels, of the vertical scroll bar.
      //
      // Returns:
      //     The default width, in pixels, of the vertical scroll bar.
      public static int VerticalScrollBarWidth { get; }

...

The recommended way to migrate a COM API is to use a RefactorLibrary file. A RefactorLibrary is a set of migration rules that direct how the translator interprets and rewrites code relating to a COM API. Here is the stub RefactorLibrary file to get us started:

Code Block
languagexml
   <RefactorLibrary>
   <Refactor id="[SYSINFO.OCX]">
   ... rules will go here ...
   </Refactor>
   </RefactorLibrary>

...

References to SysInfo.ocx cause gmStudio to load the SysInfo.ocx.xml interface description. If there is a MigFile registered, then gmStudio will also load the RefactorLibrary and modify the SysInfo API description information.  Here is an excerpt from the translation log:

Code Block
languagetext
Loading reference:[SYSINFO.OCX] ...\proj\idf\FromIdl\SYSINFO.OCX.xml
Loading reference:[SYSINFO.OCX.WinForms.Refactor] ...\proj\usr\SYSINFO.OCX.WinForms.Refactor.xml

...

proj\usr\SYSINFO.OCX.WinForms.Refactor.xml

Code Block
languagexml
<Refactor id="[SYSINFO.OCX]">
   
Rule 1)   <Migrate location="DoNotDeclace" libType="Internal" /> 

Rule 2)   <Migrate id="SysInfo" role="define" migName="SysInfo" />
   
Rule 3)   <Migrate id="ISysInfo.ScrollBarSize" type="Integer" refType="Method" migPattern="System.Windows.Forms.SystemInformation.VerticalScrollBarWidth" nPram="1"/>
      
Rule 4)   <migClass id="NetControl.SysInfo" migName="Remove.SysInfo" parent="SysInfo">
              <!-- Suppress designer code -->
          </migClass>
</Refactor>

...

Rule 3) This tells the tool to migrate references to property ScrollBarSize as System.Windows.Forms.SystemInformation.VerticalScrollBarWidth:

Code Block
languagevb
   NOT THAT: .Width = SysInfo1.ScrollBarSize
   BUT THIS: .Width = System.Windows.Forms.SystemInformation.VerticalScrollBarWidth   

...