Comment on page
In the following section, you will find a list of features available in the VBUC Tool, including Command-Line, Typing, .NET Core Support, among others.
The VBUC provides a command-line interface that allows you to upgrade your code via command line rather than using the GUI.
The command to create an upgrade solution and perform the upgrade process is:
vbuccmd <sourcePath> <solutionName(without extension)> [options*]
If you wish to upgrade an existing solution file, use the following command:
vbuccmd <solutionfile> [options*]
*The needed projects are those that reference or are referenced by one of the projects included in the upgrade. If the needed project is not in the upgrade solution, it will not be included.
Upgrade all the VB6 projects that are contained in "C:\Source Code\" to C# and leave the output in "C:\Source Code\OutputPath":
vbuccmd "C:\Source Code" MySolutionFilename /out ./OutputPath /target cs
Perform upgrade on all the projects specified in an upgrade solution file:
Visual Basic Upgrade Companion (VBUC) will switch to assessment mode once the current license is expired. This mode allows the user to perform the following actions:
- Create upgrade solutions to solve pre-migration issues i.e. missing references or files.
- Create the assessment report to quantify the efforts required for the migration task.
VBUC will be installed by default in assessment mode if a valid license file is not provided after the installation process. Once VBUC is activated, the assessment mode features will be present in the full version.
Before running the Assessment, it's necessary to follow these steps to have a successful analysis:
First, select the Assessment option from the Tools menu.
VBUC Assessment option
Once the option is selected, the Assessment window will appear.
VBUC Assessment Window
Run the Assessment, and it will analyze your VB6 project. Once the analysis is done, you can review the result in a browser by pressing the "Show Results" button. Also, there is a folder called Assessment located in the Output Path. In the next section, you can see the report files.
- Upgrade Solution (*.VBCSln)
- Used to solve:
- Internal and external References
- Project dependencies
- LOC Report.xml
- Source files per project
- Recommended upgrade order
- Lines of code (code, comments, spaces, design lines)
- Per Project
- Detail per file
- Used by Mobilize personnel for estimations.
- Information provided:
- Third-party controls:
- Used methods and properties
- Data Access components
- COM+ summary and members
- Intrinsic components
- Windows API calls
- Much more
The Dependency Analyzer enables the user to work with the solution and project dependencies. First check the output file is the correct one.
Dependency Analyzer tool
The user has to select the projects that want to analyze, once the projects are selected press the "Analyze" button. It shows all the dependencies from the corresponding projects, as shown below. In addition, by clicking the "Show Table" button it generates a .csv file with all this information.
Dependency Analyzer Result
This section describes the Typing mechanism used by the VBUC to determine the type of certain elements.
In Visual Basic 6.0, it is very common to use variables without an explicit declaration.
The Visual Basic Upgrade Companion generates all the explicit, fully-typed declarations for these variables avoiding the usage of generic data types (i.e. Object). The VBUC's type inference engine determines the most appropriate data types for variables, parameters, fields, and return values.
The Visual Basic Upgrade Companion is able to solve variable, method, and inter-project scope typing issues. The resulting source code boasts full typed variable declarations and explicit castings (if necessary) for all the variables, based on their usage and programmatic behavior.
The typing issues are simple to fix on a small scale, but it is complexity raises when combined with late binding and unusual programming practices. The manual changes required to obtain a functionally equivalent code will proportionally grow with the migration project size.
The Visual Basic Upgrade Companion will shorten the manual changes stage by providing pure, high quality, and fully typed .NET source code, allowing the entire migration project to be executed in less time than expected, reducing the overall costs and assuring the highest ROI.
The following VB6 source code sample contains three non-typed and one fixed-length string variable being used and assigned in a particular way.
Original VB6 Source Code
Private Sub typeInference()
Dim var4 As String * 50
var4 = App.Path
var1 = ArgTypeInference(var2, var3, var4, Len(var4))
Public Function ArgTypeInference(ByVal arg1 As Integer, ByVal arg2 As String, ByVal arg3 As String, ByVal arg4 As Integer)
ArgTypeInference = 1
Due to its advanced type inference mechanism, the Visual Basic Upgrade Companion's resulting source code contains clearly defined data types. For this example, var1, var2, and var3 were typed based on their usage (int and string). Also, the "ArgTypeInference" function's return value type was inferred to be int.
C# Code Generated by the VBUC
private void typeInference()
int var2 = 0;
string var3 = "";
string var4 = new string('\0', 50);
var4 = StringsHelper.GetFixedLengthString(Path.GetDirectoryName(Application.ExecutablePath), 50);
int var1 = ArgTypeInference(var2, var3, var4, Strings.Len(var4));
public int ArgTypeInference(int arg1, string arg2, string arg3, int arg4)
We also provide a mechanism that assigns custom .NET data types; it includes variables, functions, fields, properties, among others; which implies a series of changes in the code both in the declarations and in their uses.
It can be used mainly to provide the possibility to fully qualified names of statements if deemed necessary, for example, classes with the same name but with different namespaces.
Sometimes the client needs to apply custom transformation rules to specific code patterns in order to fulfill a requirement. Here are some examples:
- Rename all properties of a class of type string to str_propertyName.
- Make some classes implement a new interface and create a default method implementation for them.
- Transform all foo(str1, int1, str2, int2) method calls to otherFoo(str1, str2, int1 + int2).
- Add a new function call at the start of the methods in a class, in which the code has exactly one try-cath block.
- Remove the form_load event binding at the designer files, but keep the method handler.The VBUC team can create these custom code transformation rules to better achieve the customer-specific needs. The client only needs to define them at a macro level, by specifying the input code pattern, what conditions trigger the rule and how the output code should look like; after that, the VBUC team will handle the rest.
The Microsoft Windows application programming interface (Windows API) allows developers to call Windows OS functions directly. All programs interact with the Windows API at some point, either directly or through some other API.
Visual Basic 6 provides a mechanism to invoke methods in native code via dynamic-linked libraries (DLLs). This mechanism is possible to be used with the DECLARE statement in VB6. This statement indicates to the VB6 compiler where the procedure is located, how it is identified, its calling sequence and return type, and the string character set it uses. The Declare statement creates a reference to an external procedure and supplies this necessary information. In this way, the external procedure is called like any other method in the user code.
The following is a typical declaration and invocation of a Windows API method:
Declare Function getUserName Lib "advapi32.dll" Alias "GetUserNameA" (
ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
Dim buffer As String = New String(CChar(" "), 25)
Dim retVal As Integer = getUserName(buffer, 25)
Dim userName As String = Strings.Left(buffer, InStr(buffer, Chr(0)) - 1)
In this case, the getUser internal method displays the current user name, to do this the GetUserNameA external method is being exposed from advapi32.dll with its respective parameters and return value.
Platform Invocation Service (PInvoke) is a feature of Common Language Infrastructure implementations, like Microsoft Common Language Runtime, that enables managed code to call native code. This is the mechanism provided by .NET to invoke this kind of method.
This is an example of how the Beep external method is declared as PInvoke method, which could be used in anywhere of the user code:
extern public static int Beep(int dwFreq, int dwDuration);
The PInvoke infrastructure supplied by .NET is a mechanism for programmers in .NET to invoke external methods in an efficient and strong way. It will provide a .NET styled syntax to expose external methods and a natural way to invoke those external methods.
In general, for every external *.dll call, the VBUC generates the required interoperability data-type marshalling to allow a smooth interaction between.NET and unmanaged code. The most common changes in this feature are:
- Adds specific interoperability attributes to the signatures of upgraded API calls
- Adds error handling for the upgraded API calls.
- Generates the correct data types for pointer-type parameters
- Modifies structure generation so the marshalling of structs to Windows API calls and the copying of structures in migrated .NET applications is completely automated.
Sometimes declarations (or exposition) of an external method in .NET are easy, but invocation is sometimes complex because it has to deal with error handling, marshalling data types, and setting back values to its respective variables. This code seems to be larger and not natural, so the VBUC applies some refactoring to centralize all this code in methods that will contain all code related to those issues.
In this way, user code will be presented similar to the original, with no additional code to support marshalling or error handling, and this other code will be centralized in some files where the user can improve it or change it if necessary. Maintainability and removal of duplicated code are the main reasons why this approach is implemented in this way.
In addition, as stated above, a large amount of code for error handling, marshalling data types, especially if struct types are used to send or reassign return values to variables, must be generated in order to get the same behavior as VB6 had. All this code is generated by VBUC in those centralized files in a transparent way for all needed cases, mainly blittable types; and it will log EWIs in cases where some manual revision should be done, for non-blittable types.
The Visual Basic Upgrade Companion is able to add marshalling information to the structures used in Windows API calls. These extra attributes allow the resulting .NET code to be coherent with most of the legacy behavior found on the unmanaged code of the Windows API DLLs.
Original VB6 code:
Private Type ACTYLG_TYPE
lFirstField As Long ' <Force proper alignment>'
lIDN As Long ' INTEGER NOT NULL'
sCNCRCY_USER_IDN As String * 8 ' CHAR (8) NOT NULL'
sTABLE_ALIAS_NAME As String * 6 ' CHAR (6) NOT NULL'
iTABLE_UNQ_IDN_NI As Integer ' <Null Indicator>'
lTABLE_UNQ_IDN As Long ' INTEGER'
iTABLE_UNQ_SEQ_NUM_NI As Integer ' <Null Indicator>'
iTABLE_UNQ_SEQ_NUM As Integer ' SMALLINT'
Resulting .NET Code:
private struct ACTYLG_TYPE
public int lFirstField; // <Force proper alignment>
public int lIDN; // INTEGER NOT NULL
public char _sCNCRCY_USER_IDN; // CHAR (8) NOT NULL
public char _sTABLE_ALIAS_NAME; // CHAR (6) NOT NULL
public short iTABLE_UNQ_IDN_NI; // <Null Indicator>
public int lTABLE_UNQ_IDN; // INTEGER
public short iTABLE_UNQ_SEQ_NUM_NI; // <Null Indicator>
public short iTABLE_UNQ_SEQ_NUM; // SMALLINT
public string sCNCRCY_USER_IDN
return new string(_sCNCRCY_USER_IDN);
public string sTABLE_ALIAS_NAME
return new string(_sTABLE_ALIAS_NAME);
public static ACTYLG_TYPE CreateInstance()
ACTYLG_TYPE result = new ACTYLG_TYPE();
result._sCNCRCY_USER_IDN = new char;
result._sTABLE_ALIAS_NAME = new char;
The declaration of a VB6 external method will generate two files.
The number of files will depend on the number of libraries being used in projects. It means if there are two external methods, one using a user32 library method and the other referencing a GDI library method, the VBUC will generate two files (user32 and GDI) in a folder inside the solution named, by default, PInvokeSafeNative. It will contain any additional code related to castings, marshalling, error handling, freeing memory, and so on, and it will have the managed code that will reference the unmanaged code.
The second two generated files (named user32 and GDItoo) will be generated in the folder named PInvokeUnsafeNative, where the PInvoke declaration code will be.
Two subfolders are created, as shown below.
Inside those folders, a file will be created grouping PInvoke calls per DLL. If your API calls were, for example, to user32.dll, then a file with that name will be generated and all PInvoke calls to that DLL will be arranged inside that file. The following example shows how the code is upgraded.
Original VB6 code
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
Dim titleForm1 As String
titleForm1 = String(GetWindowTextLength(Me.hwnd) + 1, Chr$(0))
GetWindowText Me.hwnd, titleForm1, Len(titleForm1)
//File: user32.cs (safe methods)
public static class user32
public static int GetWindowText(int hwnd, ref string lpString, int cch)
return MySolutionSupport.PInvoke.UnsafeNative.user32.GetWindowText(hwnd, ref lpString, cch);
public static int GetWindowTextLength(int hwnd)
//File: user32.cs (unsafe methods)
public static class user32
[DllImport("user32.dll", EntryPoint = "GetWindowTextA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int GetWindowText(int hwnd, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpString, int cch);
[DllImport("user32.dll", EntryPoint = "GetWindowTextLengthA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int GetWindowTextLength(int hwnd);
private void Command1_Click(Object eventSender, EventArgs eventArgs)
string titleForm1 = new string(Strings.Chr(0), MySolutionSupport.PInvoke.SafeNative.user32.GetWindowTextLength(this.Handle.ToInt32()) + 1);
MySolutionSupport.PInvoke.SafeNative.user32.GetWindowText(this.Handle.ToInt32(), ref titleForm1, Strings.Len(titleForm1));
Any is a VB6 data type only used for external method declarations that indicates that it could receive any type.
This is a type that is not available in Visual Studio .NET, so it must be converted to a pointer (System.IntPtr) that contains the beginning of the memory address for each data type used in that argument.
The following example references an external method named LoadCursor. The second parameter is declared as Any.
Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Public Sub LoadSomeCursor()
Dim inst As Long, myCursorName As String
LoadCursor inst, myCursorName
These are the corresponding C# and VB.NET resultant codes. You can note the declaration of the Any argument as IntPtr in C# and Integer in VB for the Unsafe methods. The Safe methods are declared depending on the uses or invocations to the respective method. Because of that, the safe method is declared as a string in this case and requires some castings (marshalling) to be able to send this argument as a pointer and its respective setting back.
public static int LoadCursor(int hInstance, string lpCursorName)
int result = 0;
IntPtr tmpPtr = Marshal.StringToHGlobalAnsi(lpCursorName);
result = MySolutionSupport.PInvoke.UnsafeNative.user32.LoadCursor(hInstance, tmpPtr);
lpCursorName = Marshal.PtrToStringAnsi(tmpPtr);
[DllImport("user32.dll", EntryPoint = "LoadCursorA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int LoadCursor(int hInstance, System.IntPtr lpCursorName);
public static void LoadSomeCursor()
int inst = 0;
string myCursorName = "";
Public Function LoadCursor(ByVal hInstance As Integer, ByRef lpCursorName As String) As Integer
Dim result As Integer = 0
Dim tmpPtr As IntPtr = Marshal.StringToHGlobalAnsi(lpCursorName)
result = MySolutionSupport.UnsafeNative.user32.LoadCursor(hInstance, tmpPtr)
lpCursorName = Marshal.PtrToStringAnsi(tmpPtr)
Declare Function LoadCursor Lib "user32" Alias "LoadCursorA"(ByVal hInstance As Integer, ByVal lpCursorName As Integer) As Integer
Public Sub LoadSomeCursor()
Dim inst As Integer
Dim myCursorName As String = ""
The string arguments in external methods are handled almost as a general case, but the main difference is that if the argument was declared byref or byval, it always would be converted as byref in the target code. It implies handling of byref parameters being sent to that method and the declaration of that argument as VBByRefStr (in C#).
Original VB6 code
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Sub GetCurUserName()
Dim lpBuf As String * 200
GetUserName lpBuf, 200
public static int GetUserName(ref string lpBuffer, ref int nSize)
return MySolutionSupport.PInvoke.UnsafeNative.advapi32.GetUserName(ref lpBuffer, ref nSize);
[DllImport("advapi32.dll", EntryPoint = "GetUserNameA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int GetUserName([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpBuffer, ref int nSize);
internal static void GetCurUserName()
string lpBuf = new string('\0', 200);
int tempRefParam = 200;
MySolutionSupport.PInvoke.SafeNative.advapi32.GetUserName(ref lpBuf, ref tempRefParam);
lpBuf = StringsHelper.GetFixedLengthString(lpBuf, 200);
Public Function GetUserName(ByRef lpBuffer As String, ByRef nSize As Integer) As Integer
Return MySolutionSupport.UnsafeNative.advapi32.GetUserName(lpBuffer, nSize)
Declare Function GetUserName Lib "advapi32" Alias "GetUserNameA"(ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
Public Sub GetCurUserName()
Dim lpBuf As New String(Microsoft.VisualBasic.Constants.vbNullChar, 200)
Handling and passing structures to an external method are also handled differently in the PInvoke solution. In this case, a new file is generated in the PInvokeUnsafeMethods folder, which will have the structure being passed as an argument in that external method.
It implies, additionally, that any reference to that structure has to be changed to reference this new location of the structure.
Moreover, in multiple project solutions, a merge and removal of repeated structures must be done, in order to discard many duplicated structures. Sometimes there are differences between some structures that seem very similar (same name but different fields or data type fields), in this case, a renaming is added for subsequent structures and it is possible that some manual revision must be done.
Original VB6 Code
x As Long
y As Long
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Sub ObtainCursorPos()
Dim pos As POINTAPI
public static int GetCursorPos(ref MySolutionSupport.PInvoke.UnsafeNative.Structures.POINTAPI lpPoint)
return MySolutionSupport.PInvoke.UnsafeNative.user32.GetCursorPos(ref lpPoint);
[DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int GetCursorPos(ref MySolutionSupport.PInvoke.UnsafeNative.Structures.POINTAPI lpPoint);
public static class Structures
public struct POINTAPI
public int x;
public int y;
Public Function GetCursorPos(ByRef lpPoint As MySolutionSupport.UnsafeNative.Structures.POINTAPI) As Integer
Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As MySolutionSupport.UnsafeNative.Structures.POINTAPI) As Integer
Public Module Structures
Public Structure POINTAPI
Dim x As Integer
Dim y As Integer
VBUC offers the possibility to migrate your VB6 project to new .NET platforms like .NET Core 3.1, .NET 5 and .NET 6; for this, it is necessary to follow the steps to Create a VBUC solution targeting new .NET platforms.
One of the most essential differences when choosing .NET Core and .NET 5 / .NET 6 vs .NET Framework in terms of generated code, would be the .csproj or . vbproj file since the formers use the new SDK project file style.
.csproj or .vbproj file in .NET Framework
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
.csproj or .vbproj file in .NET Core or .NET 5 / .NET 6
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<PackageReference Include="Mobilize.VBUC.Helpers.DB.Essentials" Version="9.0.0" />
- The main
<Project>tag replaces the attributes with
Sdk, to indicate the SDK version to use.
- The tag
<TargetFrameworks>, depending if the project is compiled into multiple platforms.
- In this example using .NET Core, the helpers integration is done through NuGet; so the
<ProjectReference>tag is changed to
<PackageReference>, in addition to removing some unnecesary tags like
Some Upgrade Options values are not yet available for .NET Core and .NET 5 / .NET 6 migrations because of multiple reasons. In some cases, the selected feature requires a third-party library that currently does not have support for these new .NET platforms; in other cases, the third-party library might never have support. As third-party library creators update their products, we can as well enable some of these features in future releases.
The following sections provide a complete list of all Upgrade Options, grouped by category. The last column indicates the values that are enabled/disabled for .NET Core and .NET 5 / .NET 6 Migrations.