Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom GDI+ class
Storing content of the Clipboard to a bitmap file
Storing screen shot of a form to bitmap file
How to print FoxPro form
How to print a bitmap file
Vertical Label control
Capturing keyboard activity of another application with the Raw Input API (VFP9)
GDI+: Implementing image scrolling with inertia
Splash Screen for the VFP application
Displaying icons in the system tray (VFP9)
Displaying dimmed window behind VFP top-level form
Pocket PC: custom RAPI class for operating with files and folders on mobile device
Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
Monitoring clipboard content changes (VFP9)
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Obtaining names and positions for shortcuts located on the Windows Desktop
Extensible Storage Engine class library
Loading a string resource from an executable file
Attaching menu to a top-level form
How to ping a remote site using IP Helper API calls
Enumerating Processes -- WinNT
Custom HttpRequest class (WinINet)
GDI+: sending image of FoxPro form to printer
How to put a horizontal text scrolling on the form (a news line, marquee)
Winsock: how to retrieve a service information corresponding to a service 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()
    = DisplayServInfo ("pop3")
    = DisplayServInfo ("smtp")
    = DisplayServInfo ("news")
    = DisplayServInfo ("ftp")
    = DisplayServInfo ("telnet")
    = DisplayServInfo ("talk")
    = DisplayServInfo ("exec")
    = DisplayServInfo ("biff")

    = WSACleanup()
* End of Main

PROCEDURE  DisplayServInfo (lcServName)
*| 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

    LOCAL lnServentPtr, lcBuffer, lcService, lnPort, lcProt, lcAliases
    lnServentPtr = getservbyname (lcServName, .NULL.)
    IF lnServentPtr = 0
    * no service found with this name
        ? lcProt

    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)))

    ? PADR(lcService,20), STR(lnPort,5), PADR(lcProt,12), lcAliases

FUNCTION  GetAliases (lnArrayPtr)
* returns a string with alternate names for the service
* delimited with semicolons
    IF lnArrayPtr = 0

    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
        * the last array element contains null
        lnArrayPtr = lnArrayPtr + 4  && next array element
RETURN  lcResult

FUNCTION  InitWinsock()
* Initializing the Winsock service for the application
    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

    DECLARE INTEGER WSACleanup IN ws2_32
    DECLARE INTEGER getservbyname IN ws2_32 STRING name, STRING proto  
    DECLARE INTEGER htons IN ws2_32 INTEGER hostshort

    DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
        STRING @Dest, INTEGER Src, INTEGER nLength

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3126 bytes  
Created: 2001-12-17 23:43:34  
Modified: 2005-12-27 10:44:03  
Visits in 7 days: 109  
Listed functions:
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.

Copyright 2001-2017 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.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (
2 sec.Function: 'SetupCloseInfFile'
Function group: 'Setup API functions'
3 sec.Function: 'AVIStreamGetFrameOpen'
Function group: 'Windows Multimedia'
5 sec.Function: 'SizeofResource'
6 sec.Function: 'capCreateCaptureWindow'
Function group: 'Windows Multimedia'
8 sec.Function: 'GetDiskFreeSpace'
Function group: 'File System'
9 sec.Function: 'mciSendString'
Function group: 'Windows Multimedia'
11 sec.Function: 'PlaySound'
Function group: 'Windows Multimedia'
13 sec.Function: 'DrawDibDraw'
Function group: 'Windows Multimedia'
14 sec.Function: 'WSAStartup'
15 sec.Function: 'GetMonitorBrightness'
Function group: 'Monitor Configuration (Vista)'
Advertise here!