JEB
New member
Hello all,
I'm relatively experienced with vb.net, but have run into an issue that I can't seem to resolve. The issue is that I need to convert a string into a complext structure and back again. I've tried marshalling but come out with funny results.
Here's the structure
I need to convert this to a string to be able to write it to a file, then read from that file back into the structure.
I've tried the following, but while it does place the string into the structure, but it seems to mangle the data.
Any help would be very appreciated!!
I'm relatively experienced with vb.net, but have run into an issue that I can't seem to resolve. The issue is that I need to convert a string into a complext structure and back again. I've tried marshalling but come out with funny results.
Here's the structure
VB.NET:
Public Structure TLIC
Dim DBID As Integer
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=20)> Public CUSTNAME As String
Dim PASSWORD As Integer
<VBFixedString(9), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=9)> Public DISK1 As String
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=20)> Public dbName As String
<VBFixedString(75), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=75)> Public DBHOST As String
Dim MaxUsers As Short
Dim Nag As Short
Dim DEMO As Boolean
Dim SINGLE_Renamed As Boolean
Dim REPONLY As Boolean
Dim INSECURE As Boolean
Dim WEB As Boolean
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=20)> Public REPNAME As String
Dim BFUTURE1 As Byte
Dim BFUTURE2 As Byte
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=20)> Public SFUTURE1 As String
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=20)> Public SFUTURE2 As String
Dim CREATEDATE As Date
End Structure
I've tried the following, but while it does place the string into the structure, but it seems to mangle the data.
VB.NET:
Public Sub Decrypt(ByRef LIC As TLIC, ByVal LICSTR As String)
'String to Structure
Dim ByteArray() As Byte
LICSTR = decrypt2(LICSTR, LICKEY)
ByteArray = System.Text.ASCIIEncoding.Default.GetBytes(LICSTR)
Dim MyGC As GCHandle = _
GCHandle.Alloc(ByteArray, GCHandleType.Pinned)
LIC = CType(Marshal.PtrToStructure(MyGC.AddrOfPinnedObject, _
GetType(TLIC)), TLIC)
End Sub
Last edited by a moderator: