Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Obtaining MAC address through Address Resolution Protocol (ARP) request
Saving available locale records into a cursor
Using Custom FTP class (DEFINE CLASS ftp As Custom)
Memory usage info for current VFP session (WinNT only)
Retrieving default spooling directory name
Accessing a CD device (cdaudio) with Multimedia Command Strings
GDI+: converting image file to another graphics format
Retrieving the priority class for the current process
List of addresses in the AutoDial mapping database
Accessing the list of Windows Recent Documents
Extracting the name and extension parts of a path string
GetProcessVersion points at target OS
Copying files as a transacted operation (Vista)
Reading keys in the specified section of the Win.ini file
Retrieving long values associated with the class of the VFP window
Retrieving the IP-to-physical address mapping table
Basic Volume information
Pocket PC: creating new database in the Object Store and copying Contacts Database records into it
Retrieving the name of the primary domain controller (PDC) and join status information (NT/2000/XP)
WAV file recorder
Creating two-byte hashes for a list of URLs
Enumerating files opened on the network
Using LoadLibrary
Validating the heap of the calling process
Winsock: retrieving information from a host database for a given host name

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
An example of return for this sample code:
Host name: microsoft.com
IP 1: 207.46.249.190
IP 2: 207.46.249.222
IP 3: 207.46.249.27
IP 4: 207.46.134.155
IP 5: 207.46.134.190
IP 6: 207.46.134.222
 
*| struct HOSTENT {
*|   char FAR *       h_name;       0:4
*|   char FAR * FAR * h_aliases;    4:4
*|   short            h_addrtype;   8:2
*|   short            h_length;    10:2
*|   char FAR * FAR * h_addr_list; 12:4
*| }; total = 16 bytes
#DEFINE HOSTENT_SIZE  16
DO decl
 
IF Not InitWinsock()
    ? "WSAStartup failed"
    RETURN
ENDIF
 
LOCAL nHost, lcHOSTENT, lnNamePtr, lnAddrlistPtr
nHost = gethostbyname("microsoft.com")
 
IF nHost <> 0
    * copying data from the HOSTENT structure to a VFP string
    lcHOSTENT = GetMemBuf(nHost, HOSTENT_SIZE)
 
    * a pointer to the host name
    lnNamePtr = buf2dword(SUBSTR(lcHOSTENT, 1,4))
    ? "Host name:", GetMemStr(lnNamePtr)
 
    * a pointer to a null-terminated list of IP addresses
    lnAddrlistPtr = buf2dword(SUBSTR(lcHOSTENT, 13,4))
 
    * displaying IP addresses for this host
    = DisplayIPs(lnAddrlistPtr)
ELSE
* 10093 = WSANOTINITIALISED
* Either the application has not called WSAStartup, or WSAStartup failed
    ? "Error:", GetLastError()
ENDIF
= WSACleanup()
* End of Main
 
PROCEDURE  DisplayIPs (lnAddrlistPtr)
* retrieving IP addresses from the list
 
    LOCAL lnElementPtr, lnIPcount, lcDataAddress, lnDataAddress,;
        lcIPAddrBuf
 
    lnIPcount = 0  && list elements retrieved
    lnElementPtr = lnAddrlistPtr  && first member on the list
 
    * scanning the list one member by another
    * until a null member found
    DO WHILE .T.
        * the list member contains a DWORD memory address
        lcDataAddress = GetMemBuf(lnElementPtr, 4)
        lnDataAddress = buf2dword(lcDataAddress)
 
        IF lnDataAddress = 0
        * the last member on this list is null
            EXIT
        ENDIF
 
        * retrieving a DWORD with an IP address
        lcIPAddrBuf = GetMemBuf (lnDataAddress, 4)
 
        lnIPcount = lnIPcount + 1
        ? "IP " + LTRIM(STR(lnIPcount)) + ":",;
            inet_ntoa(buf2dword(lcIPAddrBuf))
 
        * shifting to the next element on the list
        lnElementPtr = lnElementPtr + 4   && DWORD
    ENDDO
RETURN
 
FUNCTION GetMemStr (lnAddr)
* returning data from a memory block as a VFP string
#DEFINE MEMSTR_BUFSIZE   128
    LOCAL lcBuffer
    lcBuffer = Repli(Chr(0), MEMSTR_BUFSIZE)
    = CopyMemory (@lcBuffer, lnAddr, MEMSTR_BUFSIZE)
RETURN SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)
 
FUNCTION GetMemBuf (lnAddr, lnBufsize)
    LOCAL lcBuffer
    lcBuffer = Repli(Chr(0), lnBufsize)
    = CopyMemory (@lcBuffer, lnAddr, lnBufsize)
RETURN lcBuffer
 
FUNCTION InitWinsock()
#DEFINE WSADATA_SIZE 398
#DEFINE WS_VERSION 0x0202
    LOCAL lcWSADATA, lnInitResult
    lcWSADATA = Repli(Chr(0), WSADATA_SIZE)
    lnInitResult = WSAStartup (WS_VERSION, @lcWSADATA)
RETURN (lnInitResult = 0)
 
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
 
PROCEDURE decl
    DECLARE INTEGER GetLastError IN kernel32
    DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING @lpWSAData
    DECLARE INTEGER WSACleanup IN ws2_32
    DECLARE INTEGER gethostbyname IN ws2_32 STRING hostname
    DECLARE STRING inet_ntoa IN ws2_32 INTEGER in_addr
 
    DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
        STRING @Dest, INTEGER Src, INTEGER nLength
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3215 bytes  
Created: 2001-12-15 09:33:39  
Modified: 2008-12-03 15:26:21  
Visits in 7 days: 128  
Listed functions:
CopyMemory
gethostbyname
GetLastError
inet_ntoa
WSACleanup
WSAStartup
Printer friendly API declarations
My comment:


#kwd: sln_winsock.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.234.42.16)
4 sec.Function: 'GdipScaleMatrix'
Function group: 'GDI+ Matrix'
7.42 min.Example: 'How to disable the Windows Clipboard (VFP9)'
Language: 'C#'
7.5 min.Example: 'Windows Shell Icons displayed and exported to ICO files (Vista)'
2.7 hrs.Example: 'Displaying the drive type value'
 Function: 'ControlService'
9.58 hrs.Example: 'Converting a hexadecimal string to an integer'
13.51 hrs.Function: 'SHAddToRecentDocs'
 Function: 'CreatePopupMenu'
17.2 hrs.Function: 'ImpersonateLoggedOnUser'
 Example: 'Form Magnifier'
Google
Advertise here!