I just ported some VB source over to PB, its compiling and executing ok, but failing when it starts its main call, and Ive got no idea why, its got me buggered. Basically the code just uses NetSessionEnum to report who is connected to your computer over NetBIOS (eg. through Explorer, etc)
Can anybody spot the bug that Ive seemingly introduced?
Original VB source: http://www.mvps.org/vbnet/code/netwo...essionenum.htm
[This message has been edited by Wayne Diamond (edited August 09, 2001).]
Can anybody spot the bug that Ive seemingly introduced?
Original VB source: http://www.mvps.org/vbnet/code/netwo...essionenum.htm
Code:
#COMPILE EXE #INCLUDE "win32api.inc" %SESS_GUEST = &H1 'session logged on as a guest %SESS_NOENCRYPTION = &H2 'session not using encryption %NERR_SUCCESS = 0& %MAX_PREFERRED_LENGTH = -1 %ERROR_MORE_DATA = 234& %LB_SETTABSTOPS = &H192 Type SESSION_INFO_502 sesi502_cname As Long sesi502_username As Long sesi502_num_open As Long sesi502_time As Long sesi502_idle_time As Long sesi502_user_flags As Long sesi502_cltype_name As Long sesi502_transport As Long End Type Declare Function NetSessionEnum Lib "Netapi32.dll" Alias "NetSessionEnum" _ (ByVal servername As Long, _ ByVal UncClientName As Long, _ ByVal username As Long, _ ByVal level As Long, _ bufptr As Long, _ ByVal prefmaxlen As Long, _ entriesread As Long, _ totalentries As Long, _ resume_handle As Long) As Long Declare Function NetApiBufferFree Lib "netapi32.dll" ALIAS "NetApiBufferFree" _ (ByVal Buffer As Long) As Long Type SESSION_INFO_50 sesi50_cname As Long sesi50_username As Long sesi50_key As Long sesi50_num_conns As Long sesi50_num_opens As Long sesi50_time As Long sesi50_idle_time As Long sesi50_protocol As Long pad1 As Long End Type Declare Function NetSessionEnum9x Lib "Netapi32.dll" _ Alias "NetSessionEnum9x" _ (ByVal pszServer As Long, _ ByVal level As Long, _ bufptr As Long, _ cbBuffer As Long, _ entriesread As Long, _ totalentries As Long) As Long Function GetSessionUserType(ByVal dwSessionType As Long) As String Select Case dwSessionType Case %SESS_GUEST: GetSessionUserType = "Guest" Case %SESS_NOENCRYPTION: GetSessionUserType = "No encryption" Case Else: GetSessionUserType = "" End Select End Function FUNCTION PBMAIN() AS LONG Dim bufptr As Long 'output Dim dwServer As Long 'pointer to the server Dim dwEntriesread As Long 'out Dim dwTotalentries As Long 'out Dim dwResumehandle As Long 'out Dim success As Long Dim nStructSize As Long Dim cnt As Long Dim usrname As String Dim bServer As String Dim si502 As SESSION_INFO_502 bServer = "\\" & Environ$("COMPUTERNAME") & CHR$(0) dwServer = StrPtr(bServer) success = NetSessionEnum(dwServer, _ 0&, _ 0&, _ 502, _ bufptr, _ -1, _ dwEntriesread, _ dwTotalentries, _ dwResumehandle) Msgbox "Success=" & STR$(success) & $CRLF & "TotalEntries=" & STR$(dwTotalEntries) & $CRLF & "EntriesRead=" & STR$(dwEntriesRead) If success = %NERR_SUCCESS And _ success <> %ERROR_MORE_DATA Then nStructSize = sizeof(si502) For cnt = 0 To dwEntriesread - 1 Msgbox "dwEntries=" & STR$(dwEntriesRead) MoveMemory _ varptr(si502), _ byval bufptr + (nStructSize * cnt), _ nStructSize usrname = str$(si502.sesi502_username) If Len(usrname) > 0 Then Msgbox usrname & ", " & _ str$(si502.sesi502_cname) & ", " & _ str$(si502.sesi502_time \ 60) & ", " & _ str$(si502.sesi502_idle_time \ 60) & ", " & _ str$(si502.sesi502_num_open) & ", " & _ str$(si502.sesi502_cltype_name) End If Next End If Call NetApiBufferFree(bufptr) End Function
[This message has been edited by Wayne Diamond (edited August 09, 2001).]
Comment