Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Winsock: retrieving information from a host database for a given host name
An alternative way of setting Form.Closable to False
GDI+: converting text strings to images and saving in a graphics file
GDI+: Using Scale and Shear transformations
Reading and setting explicit Application User Model ID for the current process (Win7)
Reading data from INI files
Retrieving System Error message strings
Using the MessageBox Win32 function
GDI+: rotating images using matrix transformations
Hiding mouse cursor
How to display the Print property sheet
Obtaining the bounding rectangle for the specified device context
Retrieving the IP-to-physical address mapping table
Saving available locale records into a cursor
Saying "Hello World!" with VFP and WinAPI
Using Custom FTP class (DEFINE CLASS ftp As Custom)
Using shared memory to exchange data between two FoxPro applications
Using the Semaphore object
Who owns the Windows Clipboard
Current System information
How to test file attributes (key method for FileExists and DirectoryExists routines)
Simulating DOEVENTS
GDI+: Storing DLL icon resources in image files
How to save registry key including its subkeys and values to a file
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: 63  
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 (107.22.127.92)
4 sec.Example: 'Obtaining names and positions for shortcuts located on the Windows Desktop'
4.68 hrs.Example: 'Displaying the associated icons and descriptions for files and folders'
4.69 hrs.
Function group: 'Process and Thread'
5.61 hrs.Function: 'FindFirstChangeNotification'
7.27 hrs.Examples
Page 59
 Function: 'SQLFreeEnv'
Function group: 'ODBC API'
9.11 hrs.Function: 'SearchPath'
11.42 hrs.Function: 'GetDesktopWindow'
11.43 hrs.Example: 'Storing content of the Clipboard to a bitmap file'
12.69 hrs.Function: 'ReadEventLog'
Function group: 'Event Logging'
Google
Advertise here!