Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
OS version and revision
Displaying dimmed window behind VFP top-level form
How to make the caption of a VFP application flashing in the Windows task bar
How to create non-blocking Winsock server
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)
Extensible Storage Engine class library
GetProcessVersion points at target OS
How to block the ALT+TAB shortcut (WinXP)
How to display Windows On-Screen Keyboard
Retrieving the name and type of all available RAS-capable devices
Retrieving the name of the primary domain controller (PDC) and join status information (NT/2000/XP)
Using an Event Object. Part B: running an application responding to events
Using FtpCommand
Retrieving list of available disk drives
Adding a background image to VFP report (VFP9, ReportListener)
Creating a clipping region from the path selected into the device context of a form
Enumerating servers of the specified type (e.g. SQL Server) in the primary domain
How to create a desktop shortcut (shell link)
Retrieveing general information about the driver and data source associated with an ODBC connection
Retrieving the User Datagram Protocol (UDP) listener table
Winsock: retrieving the standard host name and IP address for the local machine
Displaying printer-properties Property Sheet for the specified printer
GetFocus returns a HWND value
Enumerating servers of the specified type (e.g. SQL Server) in the primary domain

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
Versions:
click to open
Before you begin:
See also:
  • Enumerating network resources
  • Mapping and disconnecting network drives in FoxPro application
  • Retrieving information about shared resources on the local computer (WinNT/XP)
  •  
    * Specifies the type of software the computer is running
    #DEFINE SV_TYPE_WORKSTATION 1
    #DEFINE SV_TYPE_SERVER 2
    #DEFINE SV_TYPE_SQLSERVER 4
    #DEFINE SV_TYPE_DOMAIN_CTRL  8
    #DEFINE SV_TYPE_PRINTQ_SERVER 0x200
    #DEFINE SV_TYPE_SERVER_UNIX 0x800
    #DEFINE SV_TYPE_SERVER_NT 0x8000
    #DEFINE SV_TYPE_DOMAIN_MASTER 0x80000
    #DEFINE SV_TYPE_WINDOWS 0x400000
    #DEFINE SV_TYPE_ALL 0xFFFFFFFF
     
    DO declare
     
        * testing various server lists
    *    = EnumServers(SV_TYPE_PRINTQ_SERVER)
    *    = EnumServers(SV_TYPE_SERVER)
        = EnumServers(SV_TYPE_SQLSERVER)
    *    = EnumServers(SV_TYPE_SERVER_NT)
    *    = EnumServers(SV_TYPE_DOMAIN_CTRL)
    *    = EnumServers(SV_TYPE_ALL)
     
    PROCEDURE EnumServers(lnServerType)
    #DEFINE MAX_PREFERRED_LENGTH -1
    #DEFINE SINFO_101_SIZE       24
     
    *| typedef struct _SERVER_INFO_101 {
    *|   DWORD     sv101_platform_id;     4
    *|   LPWSTR    sv101_name;            4
    *|   DWORD     sv101_version_major;   4
    *|   DWORD     sv101_version_minor;   4
    *|   DWORD     sv101_type;            4
    *|   LPWSTR    sv101_comment;         4
    *| } SERVER_INFO_101, *PSERVER_INFO_101, *LPSERVER_INFO_101;
     
        LOCAL lnBuffer, lnCountRead, lnCountTotal, lnResult
        STORE 0 TO lnBuffer, lnCountRead, lnCountTotal
     
        WAIT WINDOW "Requesting data..." NOWAIT
        lnResult = NetServerEnum(0, 101, @lnBuffer, MAX_PREFERRED_LENGTH,;
            @lnCountRead, @lnCountTotal, lnServerType, 0, 0)
        WAIT CLEAR
     
        IF lnResult <> 0
        *  87 = The parameter is incorrect
        * 234 = More data is available
            ? "Error code:", lnResult
        ELSE
            LOCAL lcBuffer, lnBufLen, lnEntry, lnPlatformId, lnNamePtr,;
                lnMajorVer, lnMinorVer, lnSofttype, lnMemoPtr,;
                lcServerName, lcServerMemo
     
            * creating resulting cursor
            CREATE CURSOR csResult (platformid N(12), servername C(30),;
                majorver N(12), minorver N(12), softtype N(12), comment C(250))
     
            * copying the resulting array of SERVER_INFO_101 structures 
            * to a VFP string
            lnBufLen = lnCountRead * SINFO_101_SIZE
            lcBuffer = Repli(Chr(0), lnBufLen)
            = Heap2String(@lcBuffer, lnBuffer, lnBufLen)
     
            * scanning resulting array
            FOR lnEntry = 1 TO lnCountRead
                lcServerInfo = SUBSTR(lcBuffer,;
                    (lnEntry-1)*SINFO_101_SIZE+1, SINFO_101_SIZE)
     
                lnPlatformId = buf2dword(SUBSTR(lcServerInfo,  1,4))
                lnNamePtr    = buf2dword(SUBSTR(lcServerInfo,  5,4))
                lnMajorVer   = buf2dword(SUBSTR(lcServerInfo,  9,4))
                lnMinorVer   = buf2dword(SUBSTR(lcServerInfo, 13,4))
                lnSofttype   = buf2dword(SUBSTR(lcServerInfo, 17,4))
                lnMemoPtr    = buf2dword(SUBSTR(lcServerInfo, 21,4))
     
                lcServerName = GetStrFromMem(lnNamePtr)
                lcServerMemo = GetStrFromMem(lnMemoPtr)
                WAIT WINDOW lcServerName NOWAIT
     
                INSERT INTO csResult VALUES (lnPlatformId, lcServerName,;
                    lnMajorVer, lnMinorVer, lnSofttype, lcServerMemo)
            ENDFOR
            WAIT CLEAR
        ENDIF
     
        * releasing the memory block allocated regardless of the result
        * by OS within NetServerEnum call 
        = NetApiBufferFree(lnBuffer)
     
        IF USED("csResult")
            SELECT csResult
            GO TOP
            BROWSE NORMAL NOWAIT
        ENDIF
    RETURN
     
    FUNCTION GetStrFromMem(lnMemBlock)
    * converting memory allocated Unicode string to a VFP string
    #DEFINE StrBufferLength 250
        LOCAL lcBuffer
        lcBuffer = SPACE(StrBufferLength)
        = Heap2String(@lcBuffer, lnMemBlock, StrBufferLength)
        lcBuffer = SUBSTR(lcBuffer, 1, AT(Chr(0)+Chr(0),lcBuffer)-1)
    RETURN STRTRAN(lcBuffer, Chr(0),"")
     
    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 declare
        DECLARE INTEGER NetServerEnum IN netapi32;
            INTEGER servername, INTEGER level, INTEGER @ bufptr,;
            INTEGER prefmaxlen, INTEGER @ entriesread, INTEGER @ totalentries,;
            INTEGER servertype, INTEGER domain, INTEGER resume_handle
     
        DECLARE INTEGER NetApiBufferFree IN netapi32 INTEGER Buffer
     
        DECLARE RtlMoveMemory IN kernel32 As Heap2String;
            STRING @ Destination, INTEGER Source, INTEGER nLength
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    4002 bytes  
    Created: 2001-10-15 20:12:33  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 111  
    Listed functions:
    NetApiBufferFree
    NetServerEnum
    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.252.150)
    1.15 hrs.Function: 'SetBkColor'
    Function group: 'Painting and Drawing'
    1.26 hrs.Example: 'Creating the Open dialog box to specify the drive, directory, and name of a file to open'
     Example: 'Starting a dialog box for connecting to network resources (mapping network drive)'
    4.2 hrs.Example: 'URL: splitting into its component parts'
    6.08 hrs.Function: 'GdipGetDpiX'
    Function group: 'GDI+ Graphics'
    6.88 hrs.Function: 'GetCursorPos'
    Function group: 'Cursor'
    8.38 hrs.Example: 'Shortcut Menu Class'
     Example: 'Class for sound recording'
     Example: 'How to retrieve list of system DSNs (Data Source Name) with parameters'
    11.11 hrs.Function: 'NetGroupEnum'
    Function group: 'Network Management'
    Google
    Advertise here!