BYTEINSIGHT
GAPVelocity AI Studio helps you move from outdated tech stacks to the latest desktop, web, and cloud platforms—smarter, faster, and with less risk.
Choose a platform to see migration options:
Our comprehensive approach to application modernization, from assessment to production deployment.
Transformation Services
Not Sure Where to Start?
In Visual Basic 6.0, user-defined types could be passed as an argument in a Declare statement for a Windows API.
In Visual Basic .NET, a structure (user-defined type) passed as an argument in a Declare statement may require additional marshalling attributes in order to be passed correctly to the external function or subroutine. In particular, arrays and fixed-length strings may not function as expected without these attributes.
Add an Imports statement to reference the System.Runtime.InteropServices namespace and then modify the structure and the string declaration to include marshalling attributes.
Private Type MyStructure
Name AsString
Size AsInteger
End Type
DeclareFunction FunctionName Lib"MyLibrary.DLL" (ByVal rs1 As MyStructure) AsLong
PrivateStructure MyStructure
Dim Name AsString
Dim Size AsInteger
PublicSharedFunction CreateInstance() As MyStructure
Dim result AsNew MyStructure
result.Name = String.Empty
Return result
EndFunction
EndStructure
'UPGRADE_WARNING: (1050) Structure MyStructure may require marshalling attributes to be passed as an argument in this Declare statement.
DeclareFunction FunctionName Lib"MyLibrary.DLL" (ByVal rs1 As MyStructure) AsInteger
PrivateStructure MyStructure
<MarshalAs(UnmanagedType.ByValTStr)> Dim Name AsString
<MarshalAs(UnmanagedType.I4)> Dim Size AsInteger
PublicSharedFunction CreateInstance() As MyStructure
Dim result AsNew MyStructure
result.Name = String.Empty
Return result
EndFunction
EndStructure
DeclareFunction FunctionName Lib"MyLibrary.DLL" (ByVal rs1 As MyStructure) AsInteger
publicstructMyStructure
{
publicstring Name;
publicint Size;
publicstaticMyStructure CreateInstance()
{
MyStructure result = newMyStructure();
result.Name = String.Empty;
return result;
}
}
//UPGRADE_WARNING: (1050) Structure MyStructure may require marshalling attributes to be passed as an argument in this Declare statement.
[DllImport("MyLibrary.DLL")]
publicexternstaticint FunctionName( MyStructure rs1);
publicstructMyStructure
{
[MarshalAs(UnmanagedType. ByValTStr)]
publicstring Name;
[MarshalAs(UnmanagedType.I4)]
publicint Size;
publicstaticMyStructure CreateInstance()
{
MyStructure result = newMyStructure();
result.Name = String.Empty;
return result;
}
}
[DllImport("MyLibrary.DLL")]
publicexternstaticint FunctionName( MyStructure rs1);