- INDEX VB TO NET
- HOW TO MODIFY THE WAY THE CODE IS GENERATED
- ADD EXTERNAL-MARSHALLING ATTRIBUTES FOR STRUCTS
Add External-Marshalling Attributes for Structs
The Visual Basic Upgrade Companion is able to add marshalling information to the structures used in WIN-API calls. These extra attributes allows the resulting .NET code to keep coherency with most of the legacy behavior found on the unmanaged code of the WIN API dlls.
Original VB6 Code
Type 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 End Type
Resulting .NET Code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] private struct ACTYLG_TYPE { public int lFirstField; // <Force proper alignment> public int lIDN; // INTEGER NOT NULL [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] private char[] _sCNCRCY_USER_IDN; // CHAR (8) NOT NULL [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] private 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 { set { Utils.CopyValToArray(value, _sCNCRCY_USER_IDN, 8); } get { return new String(_sCNCRCY_USER_IDN); } } public string sTABLE_ALIAS_NAME { set { Utils.CopyValToArray(value, _sTABLE_ALIAS_NAME, 6); } get { return new String(_sTABLE_ALIAS_NAME); } } public static ACTYLG_TYPE CreateInstance() { ACTYLG_TYPE result = new ACTYLG_TYPE(); result._sCNCRCY_USER_IDN = new char[8]; result._sTABLE_ALIAS_NAME = new char[6]; return result; } }