I have some code I'm converting from VB6 and am experiencing problem passing a structure to a function call parameter.
Function dataBuffer (DB) parameter in VB6 is passed "AS ANY"
In VB.NET db As Any is not allowed so I'm using ByRef DataBuffer as String Parameter
Am able to pass structure as string by converting it using StructToString function shown below.
This appears to work OK and since I'm using ByRef I can get modified structure back as a string but I need to parse the string to place values back in original structure.
Now, herein lies my problem. If I have a structure "BTSTATUS" containing an array (SEG) I don't believe it's passing the array.
In this case SEG() is another Structure
How do I convert all this to a string that the function I'm calling can interpret?
How do I convert the returned DataBuffer "ByRef" back to a Structure?
Function dataBuffer (DB) parameter in VB6 is passed "AS ANY"
VB.NET:
Declare Function BtrCall Lib "wbtrv32.dll" Alias "BTRCALL" _
(ByVal OP%, _
ByVal PB$, _
[B] db As Any[/B], _
DL As Long, _
kb As Any, _
ByVal kl%, _
ByVal kn%) As Integer
In VB.NET db As Any is not allowed so I'm using ByRef DataBuffer as String Parameter
VB.NET:
Declare Function BtrCall Lib "w3btrv7.dll" Alias "BTRCALL" _
(ByVal OpCode As Short, _
ByVal Cursor As String, _
[B] ByVal DataBuffer As String, _[/B]
ByRef DataBufferLength As Short, _
ByVal KeyBuffer As String, _
ByVal KeyLength As Short, _
ByVal KeyNum As Short) As Short
Am able to pass structure as string by converting it using StructToString function shown below.
VB.NET:
Public Function StructToString(obj As Object) As String
Return String.Join(" ", obj.GetType().GetFields().Select(Function(field) field.GetValue(obj)))
End Function
This appears to work OK and since I'm using ByRef I can get modified structure back as a string but I need to parse the string to place values back in original structure.
Now, herein lies my problem. If I have a structure "BTSTATUS" containing an array (SEG) I don't believe it's passing the array.
In this case SEG() is another Structure
VB.NET:
[B] Structure BTSegment[/B]
Public iPosition As Short
Public iSize As Short
Public iFlags As Short
<VBFixedString(4)> Public slCount As String
<VBFixedString(1)> Public sType As String
<VBFixedString(1)> Public sNullValue As String
<VBFixedString(4)> Public sReserved As String
End Structure
[B] Structure BtStatus[/B]
Public iRecSize As Short
Public iPageSize As Short
Public iIndexCount As Short
<VBFixedString(4)> Public slRecordCount As String
Public iFileFlags As Short
<VBFixedString(2)> Public sReserved As String
Public iPreAlloc As Short
[B]Public Seg() As BTSegment[/B]
End Structure
How do I convert all this to a string that the function I'm calling can interpret?
How do I convert the returned DataBuffer "ByRef" back to a Structure?