Windows API Guide: GlobalFree Function


Platforms

  • Windows 95: Requires Internet Explorer 4.0 or later.
  • Windows 98: Supported.
  • Windows NT: Requires Internet Explorer 4.0 or later.
  • Windows 2000: Supported.
  • Windows CE: Requires Windows CE 1.0 or later.

Description & Usage

Sending the IPM_GETADDRESS message to an IP Address control retrieves the address stored in it. The IP address is returned in host byte order, where the field 0 value (left-most component) is in the highest-order byte and the field 3 value (right-most component) is in the lowest-order byte. For an easy way to extract the components of the IP address, use the FIRST_IPADDRESS, SECOND_IPADDRESS, THIRD_IPADDRESS, and FOURTH_IPADDRESS macros.

Return Value

The message returns the number of blank fields in the IP Address control.

Visual Basic-Specific Issues

None.

Parameters

wParam
Not used -- set to zero.
lParam
Receives the IP address stored in the control, in host byte order. If any of the fields in the control are blank, 0 is used to represent them.

Constant Definitions

Const IPM_GETADDRESS = &H466

Example

Create an IP Address control and use it to prompt the user for an IP address. When the user clicks button cmdGetDomain, the program looks up the first domain name assigned to that address.

To use this example, place a command button named cmdGetDomain on a form window. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand.

' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type  Public Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequested As Integer, lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32.dll" (addr As Long, ByVal length As Long, ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source _ As Any, ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, _ ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x _ As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, _ ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg _ As Long, wParam As Any, lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 ' *** Place the following code in a form window. *** Private hIPControl As Long  ' handle to the IP Address control ' When the form is initialized, create an IP Address control in the ' upper-left corner of the form. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE  ' identifies the control to register Dim retval As Long                        ' generic return value ' Register the IP Address control window class. With comctls .dwSize = Len(comctls) .dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. hIPControl = CreateWindowEx(0, WC_IPADDRESS, "", WS_CHILD Or WS_VISIBLE, 0, 0, 125, 20, _ Me.hWnd, 0, App.hInstance, ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long  ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long   ' the IP address, in host byte order Dim ipAddress_n As Long   ' the IP address, in network byte order Dim sockinfo As WSADATA   ' information about the Winsock implementation Dim pHostinfo As Long     ' pointer to information about the host computer Dim hostinfo As HOSTENT   ' information about the host computer Dim domainName As String  ' the primary domain name of the host computer Dim retval As Long        ' generic return value ' Verify that an IP address was entered. retval = SendMessage(hIPControl, IPM_ISBLANK, ByVal CLng(0), ByVal CLng(0)) If retval <> 0 Then Debug.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered. retval = SendMessage(hIPControl, IPM_GETADDRESS, ByVal CLng(0), ipAddress_h) If retval < 4 Then Debug.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2.2 session. retval = WSAStartup(&H202, sockinfo) If retval <> 0 Then Debug.Print "ERROR: Attempt to open Winsock failed: error"; retval Exit Sub End If ' Convert the IP address into network byte order. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer. pHostinfo = gethostbyaddr(ipAddress_n, 4, AF_INET) If pHostInfo = 0 Then Debug.Print "Could not find a host with the specified IP address." Else ' Copy the data into the structure. CopyMemory hostinfo, ByVal pHostinfo, Len(hostinfo) ' Copy the host domain name into a string. domainName = Space(lstrlen(hostinfo.h_name)) retval = lstrcpy(domainName, hostinfo.h_name) Debug.Print "Domain name is: "; domainName End If ' End the Winsock session. retval = WSACleanup() End Sub

See Also

IPM_CLEARADDRESS, IPM_SETADDRESS

Category

IP Address Control

Back to the Message list.
Back to the Reference section.


Last Modified: October 29, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/i/ipm_getaddress.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net