Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Accessing examples contained in this reference through Web Services
GDI+: retrieving list of available image encoders and image decoders
How to initiate System shutdown
How to save registry key including its subkeys and values to a file
Obtaining MAC address through Address Resolution Protocol (ARP) request
DiskFreeSpace class
Reading Internet Query options
Retrieving the rectangle area where the mouse cursor is confined
Using named pipes for interprocess communication
Using shared memory to exchange data between two FoxPro applications
Using the CopyFile
GDI+: converting image file to another graphics format
Hiding mouse cursor
Simple MAPI: how to resolve a name to unique address list entry
Who owns the Windows Clipboard
GDI+: converting text strings to images and saving in a graphics file
Pocket PC: custom RAPI class for operating with the Object Store Databases
Retrieving the IP-to-physical address mapping table
Saving available locale records into a cursor
Starting a dialog box for connecting to network resources and passing input parameters
Using the Semaphore object
Winsock: retrieving information from a host database for a given host name
Adding supplementary data to AVI files
An alternative way of setting Form.Closable to False
Winsock: how to retrieve a service information corresponding to a port

User rating: 8/10 (1 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
 
DO decl
LOCAL lnServentPtr, lnPort
 
IF InitWinsock()
    CREATE CURSOR cs (port N(5), service C(20), prot C(20), aliases C(200))
 
    FOR ii=0 TO 1024
*    FOR ii=0 TO 65535  && usually it takes awhile
 
        * converting the port number to the network byte order
        lnPort = htons(ii)
 
        * try "tcp" or "udp" instead of the .NULL.
        lnServentPtr = getservbyport (lnPort, .NULL.)
 
        IF lnServentPtr <> 0
            = DisplayServInfo (lnServentPtr)
        ENDIF
    ENDFOR
    = WSACleanup()
 
    SELECT cs
    GO TOP
    BROWSE NORMAL NOWAIT
ENDIF
* End of Main
 
PROCEDURE  DisplayServInfo (lnServentPtr)
*| struct servent {
*|   char FAR *        s_name;      0:4
*|   char FAR * FAR *  s_aliases;   4:4
*|   short             s_port;      8:4
*|   char FAR *        s_proto;    12:4
*| }; total bytes = 16
#DEFINE SERVENT_SIZE  16
 
    LOCAL lcBuffer, lcService, lnPort, lcProt, lcAliases
    lcBuffer = Repli(Chr(0), SERVENT_SIZE)
    = Heap2Str (@lcBuffer, lnServentPtr, SERVENT_SIZE)
 
    lcService = GetMemStr(buf2dword(SUBSTR(lcBuffer, 1,4)))
    lcAliases = GetAliases(buf2dword(SUBSTR(lcBuffer, 5,4)))
    lnPort    = htons(buf2word(SUBSTR(lcBuffer, 9,2)))
    lcProt    = GetMemStr(buf2dword(SUBSTR(lcBuffer, 13,4)))
 
    ? lnPort, ":", lcService
    INSERT INTO cs VALUES (lnPort, lcService, lcProt, lcAliases)
RETURN
 
FUNCTION  GetAliases (lnArrayPtr)
* returns a string with alternate names for the service
* delimited with semicolons
    IF lnArrayPtr = 0
        EXIT
    ENDIF
 
    LOCAL lcResult, lnDataPtr, lcAlias
    lcResult = ""
 
    DO WHILE .T.
        * each array element contains a pointer to data
        lnDataPtr = buf2dword(GetMemBuf(lnArrayPtr, 4))
 
        IF lnDataPtr <> 0
            lcAlias = GetMemStr(lnDataPtr)
            lcResult = lcResult +;
                Iif(Empty(lcResult), "",";") + lcAlias
        ELSE
        * the last array element contains null
            EXIT
        ENDIF
        lnArrayPtr = lnArrayPtr + 4  && next array element
    ENDDO
RETURN  lcResult
 
FUNCTION  InitWinsock()
* Initializing the Winsock service for the application
#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  GetMemBuf (lnAddr, lnBufsize)
    LOCAL lcBuffer
    lcBuffer = Repli(Chr(0), lnBufsize)
    = Heap2Str (@lcBuffer, lnAddr, lnBufsize)
RETURN  lcBuffer
 
FUNCTION  GetMemStr (lnAddr)
* returning data from a memory block
* before the first occurence of a zero byte
    LOCAL lcBuffer
    lcBuffer = GetMemBuf (lnAddr, 250)
RETURN  SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)
 
FUNCTION  buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256
 
FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
    Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
    Asc(SUBSTR(lcBuffer, 4,1)) * 16777216
 
PROCEDURE  decl
    DECLARE INTEGER WSACleanup IN ws2_32
    DECLARE INTEGER getservbyport IN ws2_32 INTEGER port, STRING proto  
    DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING @lpWSAData
    DECLARE INTEGER htons IN ws2_32 INTEGER hostshort
 
    DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
        STRING @Dest, INTEGER Src, INTEGER nLength
 
 

User rating: 8/10 (1 votes)
Rate this code sample:
  • ~
3241 bytes  
Created: 2001-12-17 23:33:58  
Modified: 2005-12-27 10:43:43  
Visits in 7 days: 66  
Listed functions:
getservbyport
htons
WSACleanup
WSAStartup
Printer friendly API declarations
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 (23.22.212.158)
4 sec.Example: 'How to display the Print property sheet'
34.77 min.Function: 'SetKeyboardState'
Function group: 'Keyboard Input'
34.82 min.Example: 'Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)'
2.51 hrs.Example: 'Extracting the name and extension parts of a path string'
5.89 hrs.Function: 'GetSysColorBrush'
Function group: 'Brush'
 Example: 'Storing screen shot of a form to bitmap file'
 Example: 'Using IsChild() for testing ThisForm.ShowWindow property'
7.16 hrs.Example: 'How to retrieve information about a cache entry (Internet Explorer)'
 Example: 'How to control Adobe Reader 9.0 (SDI mode) from VFP application'
 Example: 'Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera'
Google
Advertise here!