Notes

The following are some of the most common Notes generated by the Visual Basic Upgrade Companion.

2041 - The following line was commented

Description

This EWI appears if for some reason the line can cause compilation errors and therefore the migration tool decides to comment it out.

API Calls are Moved

The VBUC performs some code refactoring on any of the API calls that it finds by consolidating all those calls into new files. When this happens, the original VB6 Declare API statement is commented out. This line is just left as an information reference. The recommendation is to remove this line.

See also: API Call Conversion to Platform Invoke

VB6 Original Code

Public Declare Function SetTimer Lib "user32" _
   (ByVal hwnd As Long, _
   ByVal nIDEvent As Long, _
   ByVal uElapse As Long, _
   ByVal lpTimerFunc As Long) As Long

Public Function UsingAddressOf() As Integer
   Dim TimerId As Long
   TimerId = SetTimer(0, 0, 500, AddressOf TestSub)
   UsingAddressOf = TimerId
End Function

Public Function TestSub(ByVal Message As String) As Boolean
   If Message <> "" Then
      MsgBox (Message)
      TestSub = True
   Else
      TestSub = False
   End If
End Function

C# Upgraded Code

private delegate bool Module1_TestSub_Delegate(string Message);
//UPGRADE_NOTE: (2041) The following line was commented.
//[DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//extern public static int SetTimer(int hwnd, int nIDEvent, int uElapse, int lpTimerFunc);

internal static int UsingAddressOf()
{
    int TimerId = Project1Support.PInvoke.SafeNative.user32.SetTimer(0, 0, 500, (int) Marshal.GetFunctionPointerForDelegate((Module1_TestSub_Delegate) TestSub));
    return TimerId;
}

internal static bool TestSub(string Message)
{
    if (Message != "")
    {
        MessageBox.Show(Message, AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));
        return true;
    }
    else
    {
        return false;
    }
}

VB.NET Upgraded Code

Private Delegate Function Module1_TestSub_Delegate(ByVal Message As String) As Boolean
'UPGRADE_NOTE: (2041) The following line was commented.'
'Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Integer, ByVal nIDEvent As Integer, ByVal uElapse As Integer, ByVal lpTimerFunc As Integer) As Integer'

Public Function UsingAddressOf() As Integer
    Dim TimerId As Integer = Project1Support.SafeNative.user32.SetTimer(0, 0, 500, CInt(Marshal.GetFunctionPointerForDelegate(CType(AddressOf TestSub, Module1_TestSub_Delegate))))
    Return TimerId
End Function

Public Function TestSub(ByVal Message As String) As Boolean
    If Message <> "" Then
        MessageBox.Show(Message, My.Application.Info.Title)
        Return True
    Else
        Return False
    End If
End Function

6016 - Structure %1 should be within the shared file due to its use in Declare statement for a Windows API

Description

When migrating a solution made up of several projects, the use of shared files is common; in case a type is presented in that file, and one project uses this type as part of a native call (Windows API), and another project it is not; that type will exist in both, the PInvoke project and the shared file.

API Calls and structures are moved

The VBUC performs a refactoring of the API calls it encounters, along with types that can be used as parameters to those calls in new files. When that happens, the original VB6 Declare API statement is commented out. However, if there is another project that uses the same structure with no native calls in it, it must be kept in the code.

See also: API Call Conversion to Platform Invoke

VB6 Original Code

Common/Module1.bas

Type RECTType
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Project1/MainForm.frm

Private Sub Form_Resize()
    Dim nRect As RECTType

End Sub

Project2/dlls.bas

Option Explicit

Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, lpRect As RECTType, ByVal bErase As Long) As Long

C# Upgraded Code

Common/Module1.cs

//UPGRADE_NOTE: (6016) Structure RECTType should be within the shared file due to its use in a Declare statement for a Windows API. More Information: https://docs.mobilize.net/vbuc/ewis#6016
[Serializable][StructLayout(LayoutKind.Sequential)]
public struct RECTType
{
	public int Left;
	public int Top;
	public int Right;
	public int Bottom;
}

Project1/MainForm.cs

private void Form_Resize(Object eventSender, EventArgs eventArgs)
{

	Module1.RECTType nRect = new Module1.RECTType();	

}

Project2/dlls.cs

//UPGRADE_NOTE: (2041) The following line was commented. More Information: https://docs.mobilize.net/vbuc/ewis#2041
////UPGRADE_TODO: (1050) Structure RECTType may require marshalling attributes to be passed as an argument in this Declare statement. More Information: https://docs.mobilize.net/vbuc/ewis#1050
//[DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//extern public static int InvalidateRect(int hWnd, ref UpgradeSolution1Support.PInvoke.UnsafeNative.Structures.RECTType lpRect, int bErase);

UpgradeSolution1Support/PInvoke/UnsafeMethods/Structures.cs

[Serializable][StructLayout(LayoutKind.Sequential)]
public struct RECTType
{
	public int Left;
	public int Top;
	public int Right;
	public int Bottom;
}

C# Expected Code

The C# code contains two structs, one inside the shared file, the other one inside the PInvoke project. To maintain proper use of types, the type inside of the shared file can be removed or commented; and the uses of this type can be changed to the type inside the PInvoke project.

Common/Module1.cs

//[Serializable][StructLayout(LayoutKind.Sequential)]
//public struct RECTType
//{
//	public int Left;
//	public int Top;
//	public int Right;
//	public int Bottom;
//}

Project1/MainForm.cs

private void Form_Resize(Object eventSender, EventArgs eventArgs)
{

	UpgradeSolution1Support.PInvoke.UnsafeNative.Structures.RECTType nRect = new UpgradeSolution1Support.PInvoke.UnsafeNative.Structures.RECTType();

}

Project2/dlls.cs

//UPGRADE_NOTE: (2041) The following line was commented. More Information: https://docs.mobilize.net/vbuc/ewis#2041
////UPGRADE_TODO: (1050) Structure RECTType may require marshalling attributes to be passed as an argument in this Declare statement. More Information: https://docs.mobilize.net/vbuc/ewis#1050
//[DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//extern public static int InvalidateRect(int hWnd, ref UpgradeSolution1Support.PInvoke.UnsafeNative.Structures.RECTType lpRect, int bErase);

UpgradeSolution1Support/PInvoke/UnsafeMethods/Structures.cs

[Serializable][StructLayout(LayoutKind.Sequential)]
public struct RECTType
{
	public int Left;
	public int Top;
	public int Right;
	public int Bottom;
}

VB.NET Upgraded Code

Common/Module1.vb

'UPGRADE_NOTE: (6016) Structure RECTType should be within the shared file due to its use in a Declare statement for a Windows API. More Information: https://docs.mobilize.net/vbuc/ewis#6016
<Serializable> _
<StructLayout(LayoutKind.Sequential)> _
 _
Structure RECTType
	Dim Left As Integer
	Dim Top As Integer
	Dim Right As Integer
	Dim Bottom As Integer
End Structure

Project1/MainForm.vb

Private Sub Form_Resize(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles MyBase.Resize

	Dim nRect As New Module1.RECTType()

End Sub

Project2/dlls.vb

'UPGRADE_NOTE: (2041) The following line was commented. More Information: https://docs.mobilize.net/vbuc/ewis#2041
''UPGRADE_TODO: (1050) Structure RECTType may require marshalling attributes to be passed as an argument in this Declare statement. More Information: https://docs.mobilize.net/vbuc/ewis#1050
'Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Integer, ByRef lpRect As UpgradeSolution1Support.UnsafeNative.Structures.RECTType, ByVal bErase As Integer) As Integer

UpgradeSolution1Support/PInvoke/UnsafeMethods/Structures.vb

<Serializable> _
<StructLayout(LayoutKind.Sequential)> _
 _
Public Structure RECTType
	Dim Left As Integer
	Dim Top As Integer
	Dim Right As Integer
	Dim Bottom As Integer
End Structure

VB.NET Expected Code

The VB.NET code contains two structs, one inside the shared file, the other one inside the PInvoke project. To maintain proper use of types, the type inside of the shared file can be removed or commented; and the uses of this type can be changed to the type inside the PInvoke project.

Common/Module1.vb

'UPGRADE_NOTE: (6016) Structure RECTType should be within the shared file due to its use in a Declare statement for a Windows API. More Information: https://docs.mobilize.net/vbuc/ewis#6016
'<Serializable> _
'<StructLayout(LayoutKind.Sequential)> _
' _
'Structure RECTType
'	Dim Left As Integer
'	Dim Top As Integer
'	Dim Right As Integer
'	Dim Bottom As Integer
'End Structure

Project1/MainForm.vb

Private Sub Form_Resize(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles MyBase.Resize

	Dim nRect As New UpgradeSolution1Support.UnsafeNative.Structures.RECTType()

End Sub

Project2/dlls.vb

'UPGRADE_NOTE: (2041) The following line was commented. More Information: https://docs.mobilize.net/vbuc/ewis#2041
''UPGRADE_TODO: (1050) Structure RECTType may require marshalling attributes to be passed as an argument in this Declare statement. More Information: https://docs.mobilize.net/vbuc/ewis#1050
'Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Integer, ByRef lpRect As UpgradeSolution1Support.UnsafeNative.Structures.RECTType, ByVal bErase As Integer) As Integer

UpgradeSolution1Support/PInvoke/UnsafeMethods/Structures.vb

<Serializable> _
<StructLayout(LayoutKind.Sequential)> _
 _
Public Structure RECTType
	Dim Left As Integer
	Dim Top As Integer
	Dim Right As Integer
	Dim Bottom As Integer
End Structure

7001 - The following %1 (%2) seems to be dead code

Description

The VBUC analyzes the private subroutines and functions of each source code file, identifies the ones which are not used, and generates them commented out with this EWI preceding them. This improves the migration process by reducing the amount of manual work required to compile the application in .NET.

Recommendations

The target methods can be removed from the upgraded source code if they will not be used in the future. The code for these methods is upgraded but commented out. It is necessary to keep this code, it can be uncommented and used with the rest of the application.

This EWI is associated with the upgrade option Comment Out Dead Code. If it is turned off, unused code will not be commented on.

VB6 Original Code

Private Sub DeadCode()
    MsgBox "DeadCode"
End Sub

C# Upgraded Code

//UPGRADE_NOTE: (7001) The following declaration (DeadCode) seems to be dead code.
//private void DeadCode()
//{
    //MessageBox.Show("DeadCode", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));
//}

VB.NET Upgraded Code

'UPGRADE_NOTE: (7001) The following declaration (DeadCode) seems to be dead code.'
'Private Sub DeadCode()'
    'MessageBox.Show("DeadCode", My.Application.Info.Title)'
'End Sub'

8001 - Element %1 was removed

Description

This message is displayed for several maps, when an element used in VB6 is obsolete in .NET or it is just no longer needed. This EWI is displayed if an assignment to a Property that will not be supported on the target is found because the target element is no longer available or the whole statement is commented out.

VB6 Original Code

Private Sub Form_Load()
   Dim text As String
   Dim SSPanel1 As ThreeD.SSPanel

   SSPanel1.Enabled = True

   SSPanel1.Caption = ""
End Sub

C# Upgraded Code

private void Form_Load()
{
    SSPanel.Panel SSPanel1 = null;

    SSPanel1.Enabled = true;

    //UPGRADE_NOTE: (8001) Element Set property was removed.
    //SSPanel1.Caption = "";
}

VB.NET Upgraded Code

Private Sub Form_Load()
    Dim SSPanel1 As SSPanel.Panel

    SSPanel1.Enabled = True

    'UPGRADE_NOTE: (8001) Element Set property was removed.'
    'SSPanel1.Caption = ""'
End Sub

8008 - Element %1 is obsolete and should be removed

Description

In this scenario, the element is no longer available on the target platform. However, it is part of a function call or expression and the statement cannot be removed without user revision. Therefore this note is issued so the user can take proper action.

This line will cause a compilation issue and must be corrected.

VB6 Original Code

Private Sub Form_Load()
    Dim text As String
    Dim SSPanel1 As ThreeD.SSPanel

    SSPanel1.Enabled = True

    SSPanel1.Caption = ""

    text = GetMessage(SSPanel1.Caption)

End Sub

Function GetMessage(text As String)
    GetMessage = "Caption is " & text
End Function

C# Upgraded Code

private void Form_Load()
{
    SSPanel.Panel SSPanel1 = null;

    SSPanel1.Enabled = true;

    //UPGRADE_NOTE: (8008) Element Caption is obsolete and should be removed.
    string text = GetMessage(SSPanel1.Caption)
}

//UPGRADE-WARNING: Parameter text was changed from byref to byval.
public string GetMessage(string text)
{
    return "Caption is " + text;
}

VB.NET Upgraded Code

Private Sub Form_Load()
    Dim SSPanel1 As SSPanel.Panel

    SSPanel1.Enabled = True

    'UPGRADE_NOTE: (8008) Element Caption is obsolete and should be removed.'
    Dim text_Renamed As String = GetMessage(SSPanel1.Caption)

End Sub

'UPGRADE-WARNING: Parameter text was changed from byref to byval.'
Function GetMessage(ByVal text_Renamed As String) As String
    Return "Caption is " & text_Renamed
End Function

Last updated