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...
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
Restored from previous forum. Originally posted by Hi-Toro.
Ha ha! Just noticed that the forum automatically censors out swear words. Unfortunately, S-H-I-T-E-M-I-D is a genuine, valid Windows structure, defined in the Windows API (it stands for Shell Item ID)! Replace the **** above with S, H, I, and T
Restored from previous forum. Originally posted by Hi-Toro.
BTW I've been readiing the docs for this again -- I'm supposed to release the pidl.ITEMIDLIST using the IMalloc::Free call, but this COM stuff is beyond me! Anyone know what to add to this code to free 'pidl' after I'm finished using it?
Now I just want to say ****EMID ****EMID ****EMID a few times...
Restored from previous forum. Originally posted by Hi-Toro.
Doesn't seem to work. The docs state you have to get the shell's Malloc interface (I think that's its handle to memory allocated during shell function calls), and that you have to free it using the IMalloc::Free interface. I've tried this, but it doesn't work...
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
If SHGetSpecialFolderLocation_ (0, #CSIDL_NETWORK, @itemid) = #NOERROR
; Create a BROWSEINFO structure and zero it (there's probably a quicker way to do this
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 = SHBrowseForFolder_ (@bi)
EndIf
; 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