Re: [VB6] Tcp Extended Stats API / GetPerTcpConnectionEStats
Small bug with the ToggleEStat() function. My refactoring/simplification left out a couple flags. I'll post an update later on.
for now here's the updated function.
Code:
'
' Enable or disable the supplied EStat type on a TCP connection.
'
Sub ToggleEStat(ByVal Row As Long, _
ByVal EStatsType As TCP_ESTATS_TYPE, _
ByVal Enable As Boolean, _
ByVal V6 As Boolean _
)
Dim Status As Long
Dim Size As Long
Dim Rw As Long
Dim EnableRw As Byte ' BOOLEAN
Dim BandwidthRw As TCP_ESTATS_BANDWIDTH_RW_v0
If Enable Then EnableRw = TRUE_ ' TRUE == 1 == TcpBoolOptEnabled
Select Case EStatsType
Case TcpConnectionEStatsBandwidth
BandwidthRw.EnableCollectionInbound = EnableRw
BandwidthRw.EnableCollectionOutbound = EnableRw
Rw = VarPtr(BandwidthRw)
Size = LenB(BandwidthRw)
Case TcpConnectionEStatsSynOpts To TcpConnectionEStatsFineRtt
Rw = VarPtr(EnableRw)
Size = LenB(EnableRw)
Case Else
Exit Sub
End Select
If V6 Then
Status = SetPerTcp6ConnectionEStats(ByVal Row, EStatsType, _
ByVal Rw, 0, Size, 0)
Else
Status = SetPerTcpConnectionEStats(ByVal Row, EStatsType, _
ByVal Rw, 0, Size, 0)
End If
If Status <> NO_ERROR Then
wprintf "SetPerTcp{2}ConnectionEStats {0} {1} failed. {3}", _
EStatsTypeNames(EStatsType), IIf(Enable, "enabled", "disabled"), _
IIf(V6, "6", ""), DLLError(Status, "iphlpapi")
End If
End Sub
Last edited by DEXWERX; May 7th, 2018 at 08:43 AM.
Re: [VB6] Tcp Extended Stats API / GetPerTcpConnectionEStats
Hi all,
have done some more work on this. Just one question. I am interested in a bunch of stuff from TCP_ESTATS_PATH_ROD_v0 and am concerned that in particular that things like BytesRetrans is an unsigned long and my code is using a signed long and calculating the delta to log between this sample and the last sample. Will I not run into issues when the value exceeds what VB cal store in a signed long (so it goes negative I am assuming) or will the delta between the last sample (negative) and this sample (negative) actually be the correct number. Sorry if this is a dumb question !!
Re: [VB6] Tcp Extended Stats API / GetPerTcpConnectionEStats
definitely not a dumb question, but it does have a very simple answer.
There's no difference between between Signed (2's complement) and Unsigned addition or subtraction. So feel free to do your addition/subtraction using signed longs.
The only thing you need to worry about is overflow... you could use an API like VarAdd, to ignore the overflow.
just remember to display them unsigned.
Re: [VB6] Tcp Extended Stats API / GetPerTcpConnectionEStats
You can see if something like this works for you.
Code:
Public Function ULongLongSub(LeftSub As Currency, RightSub As Currency) As Currency
Dim L, R, S, HResult As Long
L = LeftSub: VarVT(L) = vbLongLong
R = RightSub: VarVT(R) = vbLongLong
'HResult = VarSub(VarPtr(L), VarPtr(R), VarPtr(S))
'If HResult < 0 Then Err.Raise HResult
S = L - R
VarVT(S) = vbCurrency
ULongLongSub = S
End Function