Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to empty the Recycle Bin
Minimizing all running applications
Number of clipboard formats available
Obtaining the bounding rectangle for the specified device context
Retrieving list of files on the FTP directory
Winsock: how to retrieve a service information corresponding to a port
Converting twips to pixels and vice versa
Enumerating sessions established on a server
Returning some basic information for the specified INF file
Displaying the drive type value
PocketPC: custom RAPI class for executing routines on remote Windows CE device
Retrieving information about MS-DOS device names using QueryDosDevice (WinNT only)
Accessing a CD device (cdaudio) with Multimedia Command Strings
Accessing examples contained in this reference through Web Services
GDI+: rotating images using matrix transformations
GDI+: Using Scale and Shear transformations
How to hot-track menu item selection in top-level form (requires VFP9)
How to view icons stored in executable files (Icon Viewer) - II
Reading and setting system access privileges for the current process
Closing Windows
How to display picture stored in enhanced-format metafile (*.emf)
How to drag a Form not using its Titlebar or Caption
How to save registry key including its subkeys and values to a file
List of addresses in the AutoDial mapping database
Winsock: how to retrieve the protocol information corresponding to a protocol 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
 
DO decl
 
IF InitWinsock()
    = DisplayProtInfo ("tcp")
    = DisplayProtInfo ("udp")
    = WSACleanup()
ENDIF
* End of Main
 
PROCEDURE  DisplayProtInfo (lcProtName)
    LOCAL lnProtoentPtr
    lnProtoentPtr = getprotobyname(lcProtName)
 
    IF lnProtoentPtr = 0
    * no protocol found with this name
        ? lcProtName
        RETURN
    ENDIF
 
*| struct protoent {
*|   char FAR *        p_name;     0:4
*|   char FAR * FAR *  p_aliases;  4:4
*|   short             p_proto;    8:4
*| }; total bytes = 12
#DEFINE PROTOENT_SIZE  12
 
    LOCAL lcBuffer, lcProt, lcAliases, lnProt
    lcBuffer = Repli(Chr(0), PROTOENT_SIZE)
    = Heap2Str (@lcBuffer, lnProtoentPtr, PROTOENT_SIZE)
 
    lcProt    = GetMemStr(buf2dword(SUBSTR(lcBuffer, 1,4)))
    lcAliases = GetAliases(buf2dword(SUBSTR(lcBuffer, 5,4)))
    lnProt    = buf2word(SUBSTR(lcBuffer, 9,2))
 
    ? PADR(lcProt,20), STR(lnProt,5), lcAliases
RETURN
 
FUNCTION  GetAliases (lnArrayPtr)
* returns a string with alternate names for the protocol
* 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 WSAStartup IN ws2_32 INTEGER wVerRq, STRING @lpWSAData
    DECLARE INTEGER WSACleanup IN ws2_32
    DECLARE INTEGER getprotobyname IN ws2_32 STRING name  
 
    DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
        STRING @Dest, INTEGER Src, INTEGER nLength
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2755 bytes  
Created: 2001-12-20 07:20:26  
Modified: 2005-12-27 10:44:42  
Visits in 7 days: 82  
Listed functions:
getprotobyname
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 (54.224.79.93)
28.53 min.Example: 'Sending email messages with Simple MAPI'
51.53 min.Function: 'SCardListReaderGroups'
51.58 min.Example: 'Using the SetErrorMode for determining if a floppy drive is ready'
1.43 hrs.
Function group: 'Virtual Hard Disk (Win7)'
3.93 hrs.Function: 'HeapAlloc'
 Examples
Page 4
7.1 hrs.Example: 'Establishing connection using the SQLDriverConnect'
Language: 'C++'
 Example: 'How to prevent users from accessing the Windows Desktop and from switching to other applications'
9.17 hrs.Example: 'Retrieving the User Datagram Protocol (UDP) listener table'
 Example: 'Using File Mapping for enumerating files opened by Visual FoxPro'
Google
Advertise here!