Posted: Sun Feb 16, 2003 9:27 pm
Restored from previous forum. Originally posted by Hi-Toro.
This opens a dialog box and lets you select a computer on the network; also returns IP address of a named PC. Should be useful for LAN chat programs and stuff...
--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
This opens a dialog box and lets you select a computer on the network; also returns IP address of a named PC. Should be useful for LAN chat programs and stuff...
Code: Select all
Procedure.s GetNetworkComputer (parentwindow, title$)
; Note: take a look at the Win32 docs for SHBrowseForFolder, as you can easily
; modify this function to return printers, etc...
#CSIDL_NETWORK = $12
; Weird Windows structure (holds an internal reference to a folder location, I think)...
Structure ****EMID
cb.b
abID.b[1]
EndStructure
; And more...
Structure ITEMIDLIST
mkid.****EMID
EndStructure
; Create an item, whatever that may be, and stuff the required location into it...
*itemid.ITEMIDLIST = #NULL
SHGetSpecialFolderLocation_ (0, #CSIDL_NETWORK, @*itemid) = #NOERROR
; Create a BROWSEINFO structure and zero it (there's probably a quicker way to do this :wink:
DefType.BROWSEINFO bi
For b = 0 To SizeOf (BROWSEINFO) - 1
PokeB (@bi + b, 0)
Next
; Create a buffer for the computer name to be placed in...
computer$ = Space (#MAX_PATH)
; Fill in the structure...
bi\hwndOwner = parentwindow
bi\pidlRoot = *itemid
bi\pszDisplayName = @computer$
bi\lpszTitle = @title$
bi\ulFlags = #BIF_BROWSEFORCOMPUTER
; Show the browser dialog...
pidl.ITEMIDLIST = SHBrowseForFolder_ (@bi)
; Set the computer name to "" if there's nothing returned...
If computer$ = Space (#MAX_PATH)
computer$ = ""
EndIf
ProcedureReturn computer$
EndProcedure
Procedure.s GetNetworkComputerIP (computer$)
; Structure used for host information...
Structure HOSTENT
h_name.l
h_aliases.l
h_addrtype.l
h_length.l
h_addr_list.l
EndStructure
If computer$
; Create WSA version number (damn, ugly!)...
high.b = 1: low.b = 1
DefType.w wsaversion
PokeB (@wsaversion, high) ; Gotta poke major version number into low byte...
PokeB (@wsaversion + 1, low) ; ... and minor version number into high byte
; Try to access Windows sockets stuff...
If WSAStartup_ (wsaversion, wsa.WSAData) = #NOERROR
; Get host information for named computer...
*host.HOSTENT = gethostbyname_ (computer$)
If *host #NULL
; Get IP address of named computer...
ip$ = PeekS (inet_ntoa_ (PeekL (*host\h_addr_list)))
EndIf
; Close Windows sockets stuff...
WSACleanup_ ()
EndIf
ProcedureReturn ip$
EndIf
EndProcedure
; D E M O . . .
; Show network computer selection dialog (note that '0' can be replaced by a window handle)...
pc$ = GetNetworkComputer (0, "Select a local computer...")
If pc$
; Get IP address of selected computer...
ip$ = GetNetworkComputerIP (pc$)
MessageRequester ("Selected PC...", "You selected " + pc$ + ", at IP address " + ip$, #MB_ICONINFORMATION)
EndIf
See ya,
James L Boyd.
http://www.hi-toro.com/
--