Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Retrieving the priority class for the current process
Retrieving top-child window for the VFP form
Converting path to original case
Displaying Windows shell folders in TreeView control with Visual FoxPro FLL
MapiSendMail class for Visual FoxPro application
Obtaining a handle to the desktop associated with the calling thread
URL: splitting into its component parts
Using FrameRgn for displaying system colors
Yet another modal dialog: now HTML-based
How to download a file from HTTP server using URL Monikers functions
How to find when the application started
How to start the screen saver and how to find whether the screen saver is active
Uploading file to the FTP server using InternetWriteFile
URL: converting unsafe characters and spaces into escape sequences
Converting a decimal string to an integer
Converting long file names to the short format and vice versa
Copying strings through the global memory block
GDI+: cropping images
Loading a string resource from an executable file
Using SQLBrowseConnect to connect to a data source through a number of iterative calls (SQL Server)
Winsock: changing the byte ordering
Testing an ODBC connection for supporting specific functionality
Using GetSysColor
Adding printer to the list of supported printers for the specified server
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: 83  
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.242.188.217)
2.61 hrs.Function: 'SQLBrowseConnect'
5.12 hrs.Example: 'Converting command-line string to a set of Unicode argument strings (WinNT only)'
9.2 hrs.
Function group: 'Window Procedure'
 Function: 'GetProcessTimes'
Function group: 'Process and Thread'
 Function: 'CeGetSystemInfo'
Function group: 'Remote Application Programming (RAPI)'
11.04 hrs.Function: 'GetSystemPowerStatus'
 Example: 'Validating the heap of the calling process'
11.05 hrs.Updates
12.1 hrs.Function: 'IsIconic'
Function group: 'Window'
19.41 hrs.Examples
Google
Advertise here!