Skip to content

Blog

Using RefactorLibraries for Automated COM API Replacement

Upgrading a real-world VB6 application typically requires replacing COM APIs with .NET APIs. gmStudio uses and open, extensible COM type system to facilitate automating these types of COM upgrades. The COM type system used by the upgrade process is declared in a set of files called Interface Description Files (IDFs). IDFs are XML text files that declare all of the elements of an API: the enumerations, classes, structs, etc. IDFs are detailed dow the level of individual method arguments. An standard set of IDFs are generated for you by gmStudio from the COM binaries used by your application. The IDF generation process usually works completely automatically, but in some cases it is necessary to manually locate and generate IDFs for atypical COM type libraries.

Standard IDFs are designed to direct the translation to use either a stub framework exposing the original COM API or an interop wrapper around the COM binary. The default is to let the gmStudio generate the stub framework and referecne it in the translated application code. This state of translation: referencing a stub framework is an initial step to facilitate building and verifying the standard translations. Once this step is completed, the IDFs may be modified to direct the translator to replace the COM APIs with some other API. The replacement techniques require modifying the IDF to change how its elements are referenced in translated code.

There are two ways to modify IDFs:

  • Modify the IDF XML files directly, or
  • Modify the IDF information with refactoring commands

This document describes how to use the second approach. See this article for a discussion of COM Replacements by modifying IDFs directly.

A Mig.IDF file is an XML text file that contains refactoring commands associated with a given IDF. Using Mig.IDF files provides a more deliberate, and arguably superior approach to organizing COM migration rules for each API. Compared to COM replacements done by modifying IDFs directly, using Mig.IDF files can be easier to create and easier to see what is being migrated because the rules are more clearly identified and explicit. Note also that Mig files are applied to the generated IDF, so re-generating the IDF will not disturb the associated Mig.IDF file.

An Example: MSComCtlLib.ProgressBar to a WinForms.ProgressBar

Section titled “An Example: MSComCtlLib.ProgressBar to a WinForms.ProgressBar”

Let’s say you want to migrate MSComCtlLib.ProgressBar to a WinForms.ProgressBar. This is a pretty easy migration as the WinForms control is very similar to the COM control.

First you create a Mig.IDF file for the MSComCtl.ocx API taht contains progress bar. This file must be named “Mig.” followed by the name of the COM IDF containing the class/control that you want to migrate in this case, the name is Mig.MSComCtl.ocx.xml. An initial version of this file is shown below.

<RefactorLibrary>
<Refactor id="[MSComCtl.ocx]">
<Migrate location="DoNotDeclare" migName="System.Windows.Forms" />
<Migrate id="IProgressBar.Min" migName="Minimum" />
<Migrate id="IProgressBar.Max" migName="Maximum" />
<Migrate id="IProgressBar.Appearance" migStatus="mustCorrect" />
<migClass id="NetControl.ProgressBar" migName="System.Windows.Forms.ProgressBar" parent="ProgressBar">
<property id="Location" value="(Left,Top)" nPram="2" migPattern="new System.Drawing.Point(%1d, %2d)" />
<property id="Name" type="string" value="SYM.name" />
<property id="Size" value="(Width,Height)" nPram="2" migPattern="new System.Drawing.Size(%1d, %2d)" />
<property id="TabIndex" type="Integer" value="TabIndex" default="0" />
<!-- NOT MAPPED for designer Appearance = System.Windows.Forms.AppearanceConstants.cc3D; -->
</migClass>
</Refactor>
</RefactorLibrary>

The Mig.IDF file should be placed in “user” folder in the project work space along with the other upgrade scripts, code, and documentation you are developing for your upgrade solution.

For this example, I placed the mig file in the usr\idf\3pc folder in my project workspace.

Next, you activate the Mig.IDF by taking advantage of gmStudio’s folder conventions. For example, the following ScriptRule sets the primary configuration folder to usr\idf\3pc then loads the IDF. The tool will search for the IDF and load it then search for the Mig.IDF file and apply the refactoring commands.

<ScriptRule id="MSComCtlLib">
<Option>
<Select Target="..\usr\idf\3pc"/>
<reference id="MSComCtl.ocx" />
</Option>
</ScriptRule>

Finally, this ScriptRule may integrated into the main translation script template using a <ScriptRule> command:

<gmBasic>
<Storage Action="Create" Identifier="%JobId%" />
<select Target="%UserFolder%" />
<Select Local="%IdfFromCodeFolder%" />
<Select System="%IdfFromIdlFolder%" />
...
<ScriptRule id="MSComCtlLib" />
<Compile Project="%SrcPath%" />
<Analyse />
<Output Status="New" Filename="%BndPath%" />
<Author />
<Storage Action="Close" />
</gmBasic>

When translator processes any VBP code that references this API, it will do so according to the modified IDF rules.

Basic Processor V30.76(07/18/18) System Build(07/18/18 5:26:53)
...
Loading reference:[MSComCtl.ocx] \gmClients\Client\poc\proj\idf\FromIdl\MSComCtl.ocx.xml
Loading reference:[Mig.MSComCtl.ocx] \gmClients\Client\poc\proj\usr\idf\3pc\Mig.MSComCtl.ocx.xml
...

gmStudio Release News: July 2018 Updates

gmBasic is a powerful code transformation tool that reads, interprets, and rewrites VB6/ASP/COM systems for .NET (using either C# or VB.NET). We are always improving gmBasic to make it more robust and flexible so that it produces cleaner, more correct results. This distribution, Version 30.75, includes several enhancements:

  • Improves the general ability to produce accurate, build-complete .NET code systems from VB6 code (most recently making enhancements needed to upgrade a large insurance application with 26 inter-related VBPs referencing 592 code files containing 575K LOC and 34 third-party-COM components)
  • Improves accuracy and readability of certain complex conditional expressions
  • Improves default C# coding style to use lightweight object-oriented coding conventions (formerly, this required the “SubSystem=loc” option)
  • Improves default VB.NET coding style to favor using VB.NET run-time support rather than extension methods
  • Improves handling identifiers containing international characters

gmStudio: Upgrade Solution Development Environment

Section titled “gmStudio: Upgrade Solution Development Environment”

Powered by gmBasic, gmStudio is a development environment for creating high-performance, custom VB6/ASP/COM-to-.NET upgrade solutions. We are always adding functionality to gmStudio and making it easier to use. This distribution includes several enhancements:

  • Adds flexibility of deployment by allowing the user to specify .NET project file and folder naming conventions as part of each gmStudio project’s settings
  • Adds options for project task name conventions to better support different types of legacy project naming conventions
  • Adds support for setting CodePage in the .NET project file
  • Adds support for setting .NET Project Type GUIDs needed for WPF upgrades
  • Improves conventions for StartUpObject conventions for WPF upgrades
  • Improves handling of MigrationSupport stub classes in integrated translations
  • Improves handling of international characters in all Search Reporting functions
  • Adds stable-but-unique Project GUID generation for all .NET projects
  • Improves gmStudio About Box Reporting
  • Corrects screen layout issues when running Windows with Text Size greater than 100%
  • Improves Analytics Reports and model Audits to use gmMetrics, a gmSLAPI application
  • Improves default handling of Last Message field to avoid spurious differences between versions of gmProj files
  • Adds support for interpreting foreign language build logs
  • Adds support for using the %ProjFolder% token in Solution File Generator project list
  • Improves log content for Solution File Generator
  • Improves reporting of #INFO messages in Translation Log Reports
  • Adds sort indicators to ListView column headers
  • Improves integration with upgrade tasks using a gmslAPI executable
  • Improves Configuration Form User files listing to include sub-folders
  • Adds support for Form-to-XAML in the Side-by-Side Viewer for WPF upgrades
  • Adds option to skip running translations in Upgrade Wizard thus running only the metrics reports
  • Improves handling of very large (>64MB) log files (e.g., when using diagnostics)

gmSLAPI: a .NET API for Developing Advanced Upgrade Solutions

Section titled “gmSLAPI: a .NET API for Developing Advanced Upgrade Solutions”

Powered by gmBasic, gmslAPI is a .NET API for automating the gmBasic upgrade engine and accessing the semantic models produced by our unique linguistic compilation technology. gmSLAPI also includes classes to facilitate integrating with gmStudio and managing complex upgrade rules.

  • Improves organization of gmslAPI classes with namespaces
  • Improves handling conditions on nested rules in ScriptRules.xml
  • Improves ScriptRules logger to use the LogMessage API

gmStudio ships with a collection of sample upgrade rules that can be used to add custom features to your upgrade solution. These XML documents and gmSL scripts are distributed as source that you may modify to fit your unique requirements. The sample rules were updated to reflect the latest product improvements and conventions.

  • Improves standard ScriptRules.xml template
  • Improves standard translation templates to assume new C# dialect rather than the deprecated “SubSystem=loc” option
  • Improves Analytics Reports and Audits Reports script templates to use gmMetrics
  • Changes default handling of Line to migrate to MigrationSupport.Line rather than Label
  • Removes SubSystem=loc; The loc conventions are now the default for translation to C#
  • Removes SubSystem=lob; VB.NET bias is now the default for translation to VB.NET
  • Improves migration of VB6 File System Listbox controls to facilitate stub framework integration

Great Migrations publishes a number of sample VB6/ASP upgrade solutions to illustrate the capabilities of gmStudio. The sample upgrade solutions were updated to reflect the latest product improvements and conventions.

  • Samples updated to reflect changes to SubSystem changes
  • Samples updated to reflect changes to MigrationSupport.UI
  • Improves packaging of “All Samples” content

gmStudio Release News: Wednesday, April 3, 2018

Great Migrations is pleased to announce a major break through in software re-engineering: a .NET API for automating the gmBasic upgrade engine and accessing the semantic models produced by our linguistic compilation technology.

Our goal for this API is to provide the most powerful development platform for building advanced upgrade solutions. The API integrates the features of the Great Migrations Programming Language (gmPL) with Great Migrations Scripting Language (gmSL). The XML-based gmPL has been used for upgrade scripts as well as meta-language and COM interface description files. The C-like gmSL API has been used extensively for dynamic code templates, deep code analysis, and advanced transformations. gmPL and gmSL provide access to an extensive collection of gmBasic commands, events, and operations, but they lack key features of modern development platforms such as interactive debugging and intellisense. The new .NET-based gmslAPI addresses these limitations and provides greater access to the full power of the gmBasic translation engine. Of course, developers building upgrade solutions using gmslAPI can also use other .NET language and framework features allowing more sophisticated upgrade solutions integrating a wider array of information.

The API includes special purposes classes to help you integrate API-based EXE upgrade tasks with gmStudio and customize their behavior. EXE upgrades tasks can be used in gmStudio using procedures very similar to those for gmPL script tasks. The main difference is the EXE tasks are implemented in C# (or VB.NET) using Visual Studio while gmPL script tasks are implemented in XML using your favorite code editor. We have already developed a C# version of the WPF transformation logic using this API and also used it with C# to implement several very large multi-feature upgrade solutions. And early preview of API documentation is here and additional documentation and samples will be published soon. Please Contact us directly if you are interested in discussing how this technology can help you.

gmBasic is a powerful code processor that reads, interprets, and rewrites VB6/ASP/COM systems as .NET (C# or VB.NET). We are always improving gmBasic to make it more robust and flexible and so that it produces cleaner, more correct results. This distribution, Version 30.68, includes several enhancements:

  • Adds a .NET API for accessing the gmBasic operations and semantic information models
  • Improves handling of nested collections and dictionaries
  • Improves separation of declarations and executable code into codebehind and markup for ASP using alternate statement separator
  • Improves upgrading properties with optional arguments to a method

gmStudio: Upgrade Solution Development Environment

Section titled “gmStudio: Upgrade Solution Development Environment”

Powered by gmBasic, gmStudio is a development environment for creating high-performance, custom VB6/ASP/COM to .NET upgrade solutions. We are always adding functionality to gmStudio and making it easier to use. This distribution includes several enhancements:

  • Improves ScriptRules file handling by allowing ScriptRule elements to be conditional.
  • Adds support for gmslAPI and upgrade tasks using a custom EXE rather than gmBasic
  • Improves Filter to Selection using both the Source Name and Task Tag
  • Improves Search Reports allow for XML files that are not in an expected GM meta-data format.
  • Improves Support for handling text files with different EOL conventions
  • Improves Library Description value reported in the Source References Report
  • Adds support for %ProjectFolder% parameter in Visual Studio Solution Generator project List
  • Improves IDF path reported in the Source Reference Report for ASP include references
  • Improves default ASP Site Upgrade Projects generated by Project Wizard; setting job type to MULTI, not CUSTOM

gmStudio ships with a collection of sample upgrade rules that can be used to add custom features to your upgrade solution. These XML documents and gmSL scripts are distributed as source that you may modify to fit your unique requirements. The sample rules were updated to reflect the latest product improvements and conventions.

  • Improves scrrun.dll.xml sample
  • Improves default ScriptRules.xml file and documentation

Great Migrations publishes a number of sample VB6/ASP upgrade solutions to illustrate the capabilities of gmStudio. The sample upgrade solutions were updated to reflect the latest product improvements and conventions.

gmStudio Release News: 13, February 2018

New gmStudio Case Studies and Testimonials

Section titled “New gmStudio Case Studies and Testimonials”

A recent customer allowed us to publish a brief description of their ASP/COM upgrade project and their testimonial of success with gmStudio. Learn how a small team accelerated their ASP site upgrade effort with the help of gmStudio. Read the article

gmBasic is a powerful code processor that reads, interprets, and rewrites VB6/ASP/COM systems as .NET (C# or VB.NET). We are always improving gmBasic to make it more robust and flexible and so that it produces cleaner, more correct results. This distribution, Version 30.63, includes several enhancements:

  • Prevents authoring duplicate members in COM stub classes when a coclass implements same-named members for multiple interfaces
  • Improves accuracy of Reference Report for explicit calls to user-defined event handlers
  • Improves upgrading the Select Case Statement
  • Begins work on a .NET API for developing custom VB6/ASP/COM upgrade solutions

gmStudio: Upgrade Solution Development Environment Update

Section titled “gmStudio: Upgrade Solution Development Environment Update”

Powered by gmBasic, gmStudio is a development environment for creating high-performance, custom VB6/ASP/COM to .NET upgrade solutions. We are always adding functionality to gmStudio and making it easier to use. This distribution includes several enhancements:

  • Adds support for using VS2017 IDE and the latest MSBuild
  • Adds support for setting .NET Framework Version using a registry command; for example:
<Registry type="VSConfiguration" source="FrameworkVersion" target="v4.0.0" />
  • Improves Task Filter performance
  • Adds Filter to Selection operation to the task list context menu
  • Improves Global Stubs Report to create a build script for compiling a COM Stub Framework
  • Adds Copy to Search operation to copy selected text to the Search Panel
  • Improves .NET Code Scan when searching for multiple pattern strings
  • Improves support for recognizing Custom Translation scripts
  • Improves accuracy of late-bound dependencies reported in the Source References Report
  • Improves gmStudio Installer to meet all Windows 10 Desktop Product Certification Requirements
  • Adds Support for UI Color Themes even if they are not installed with Visual Studio
  • Improves accuracy of containing member reported in Source Scan Report
  • Improves handling of comments when searchingUser files or Custom files

gmStudio ships with a collection of sample upgrade rules that can be used to add custom features to your upgrade solution. These XML documents and gmSL scripts are distributed as source that you may modify to fit your unique requirements. The sample rules were updated to reflect the latest product improvements and conventions.

  • Improves GlobalStubs.xml Script used to generate a COM stub framework
  • Improves GlobalStubs.cmd Script used to build a COM stub framework
  • Improves the Search Reporting templates

Great Migrations publishes a number of sample VB6/ASP upgrade solutions to illustrate the capabilities of gmStudio. The sample upgrade solutions were updated to reflect the latest product improvements and conventions.

  • Adds another WPF upgrade sample for the Calculator application (both C# and VB.NET)

Announcing the New FORTRAN-to-C# Modernization Tool

Special Announcement: new FORTRAN-to-C# tool

Section titled “Special Announcement: new FORTRAN-to-C# tool”

gmFortran, our world-class FORTRAN-to-C Translator, is being enhanced to support FORTRAN-to-C#. Our development efforts have already produced a tool that can translate the GSA FORTRAN Compiler Validation Suite to functionally equivalent C#. Please contact us if you are interested in participating in the beta-test.

gmBasic is a powerful code processor that reads, interprets, and rewrites VB6/ASP/COM systems as .NET (C# or VB.NET). We are always improving gmBasic to make it more robust and flexible and so that it produces cleaner, more correct results. This distribution, Version 30.60, includes several enhancements:

  • Improves translating ASP render functions containing markup with in-line if-then blocks
  • Removes reference to VisualBasic.PowerPacks assembly when using a stub framework strategy
  • Adds support for DoEvents called as a function returning integer
  • Corrects issue with analysing references to module constants
  • Corrects several patterns relating to UserControl methods
  • Allows referencing MigrationSupport assembly when using local stub framework strategy

gmStudio: Upgrade Solution Development Environment Update

Section titled “gmStudio: Upgrade Solution Development Environment Update”

Powered by gmBasic, gmStudio is a development environment for creating high-performance, custom VB6/ASP/COM to .NET upgrade solutions. We are always adding functionality to gmStudio and making it easier to use. This distribution includes several enhancements:

  • Improves ASP Translation scripts generated by the New Project Wizard
  • Accelerates default ASP project setup by limiting the source scan to .asp, .asa, and .inc files.
  • Adds sorting to source file list in the New Project Wizard
  • Corrects screen layout problems when running Windows with text size greater then 100%
  • Improves Search Template Reporting by using ’^’ rather than ” as escape character
  • Adds Find-Count Reporting for XML file search results
  • Improves Search-Replacement facility by allowing replacing multi-line regex patterns
  • Improves Project Summary Report to use case-insensitive tabulation for COM reference summary
  • Improves performance of Search Template Reporting
  • Adds user-defined events to Source Members Report
  • Corrects reporting the parent of enum entries in the IDF Search Report
  • Adds whole-word, case-insenstive, and regex options when searching code listings in the Side-by-Side Form
  • Adds support for opening Definitions Report at specific record from Search Results list

gmStudio ships with a collection of sample upgrade rules that can be used to add custom features to your upgrade solution. These XML documents and gmSL scripts are distributed as source that you may modify to fit your unique requirements. The sample rules were updated to reflect the latest product improvements and conventions.

  • Improves web site deployments and functional testing logic in the default User Command Script template
  • Improves the GlobalIncludes Script template
  • Improves the Search Reporting Script template
  • Improves usability of MSWord Interop upgrade rules file
  • Improves search pattern samples in the default Code Scan Terms file

Great Migrations publishes a number of sample VB6/ASP upgrade solutions to illustrate the capabilities of gmStudio. The sample upgrade solutions were updated to reflect the latest product improvements and conventions.

Download: