Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Using FillMemory
Using NetWkstaTransportEnum to obtain MAC Address of remote server
Winsock: creating a socket that is bound to a specific service provider
Comparing dimensions of the VFP main window with _SCREEN properties
Dial the Net Automatically
Enumerating ODBC drivers available on the local computer
How to create a desktop shortcut (shell link)
Reading parameters of streams in AVI file
Reading the structure of VFP main menu
Retrieving list of available disk drives
Writing entries to custom Event Log
Accessing LSA Policy object (Local Security Authority)
Converting command-line string to a set of Unicode argument strings (WinNT only)
Enumerating the subkeys of a user-specific key
Finding out if the current user is the Guest account
Retrieving information about all users currently logged on to the workstation (WinNT only)
Retrieving IP statistics for the computer
Using mailslots to send messages on the network
Using the Semaphore object to allow only one instance of VFP application running
How to get Special Folders paths
Using the DeleteFile
Validating URLs using moniker functions
Converting an HTTP time/date string to a SYSTEMTIME structure
Creating a clipping region from the path selected into the device context of a form
Using NetWkstaTransportEnum to obtain MAC Address of remote server

User rating: 10/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
Before you begin:
See also:
  • SendARP function
  • How to retrieve adapter information for the local computer (including MAC address)
  • Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
  • How to ping a remote site using IP Helper API calls
  • How to ping a remote site using ICMP API calls

  •  
    #DEFINE MAX_PREFERRED_LENGTH -1
    #DEFINE NERR_Success 0
     
        DO decl
     
        LOCAL cServer, cBuffer, hBuffer, nBufsize,;
            nEntriesRead, nEntriesTotal
     
        * for other computers, not the local computer,
        * convert server name to Unicode
        cServer = null
    *    cServer = StrConv("myserver"+Chr(0), 5)
     
        cBuffer = Repli(Chr(0), 16384)
        STORE 0 TO hBuffer, nBufsize, nEntriesRead, nEntriesTotal
     
        nResult = NetWkstaTransportEnum(cServer, 0, @hBuffer,;
            MAX_PREFERRED_LENGTH, @nEntriesRead, @nEntriesTotal, 0)
     
        IF nResult <> NERR_Success
        * 5=ERROR_ACCESS_DENIED -- connect to the server
        * 53=ERROR_BAD_NETPATH
        * 124=ERROR_INVALID_LEVEL
        * 234=ERROR_MORE_DATA
        * 1113=ERROR_NO_UNICODE_TRANSLATION
        * 2123=The API return buffer is too small
            = NetApiBufferFree(hBuffer)
            ? "Error code:", nResult
            RETURN
        ENDIF
     
        ? "Entries read:", nEntriesRead
     
        * obtain size of the buffer
        = NetApiBufferSize(hBuffer, @nBufsize)
     
        cBuffer = Repli(Chr(0), nBufsize)
        CopyMemory(@cBuffer, hBuffer, nBufsize)
     
    *    ? cBuffer
     
    * this is how you can view and analyze the buffer
    * populated by NetWkstaTransportEnum function
    *    CREATE CURSOR cs (cc C(1), aa I)
    *    FOR ii=1 TO Len(cBuffer)
    *        ch = SUBSTR(cBuffer, ii,1)
    *        INSERT INTO cs VALUES (m.ch, Asc(m.ch))
    *    ENDFOR
     
    *|typedef struct _WKSTA_TRANSPORT_INFO_0 {
    *|  DWORD wkti0_quality_of_service; 0:4
    *|  DWORD wkti0_number_of_vcs;      4:4
    *|  LPWSTR wkti0_transport_name;    8:4
    *|  LMSTR wkti0_transport_address; 12:4
    *|  BOOL wkti0_wan_ish;            16:4
    *|} WKSTA_TRANSPORT_INFO_0, ... total 20 bytes
    #DEFINE TRANSPORT_INFO_SIZE 20
     
        LOCAL nIndex, hName, hAddress, cName, cAddress, ch
        CREATE CURSOR cs (devname C(70), srvaddress C(50))
     
        * retrieving device names and server address for existing
        * transport protocols
        FOR nIndex=1 TO nEntriesRead
            hName = buf2dword(SUBSTR(cBuffer,;
                (nIndex-1)*TRANSPORT_INFO_SIZE+9,4))
     
            hAddress = buf2dword(SUBSTR(cBuffer,;
                (nIndex-1)*TRANSPORT_INFO_SIZE+13,4))
     
            hName = hName - hBuffer  && decrease by initial offset
            cName = ""
            DO WHILE .T.
                ch = SUBSTR(cBuffer, hName, 2)
                IF ch = Chr(0)+Chr(0) Or hName > Len(cBuffer)
                    EXIT
                ENDIF
                cName = cName + ch
                hName = hName + 2
            ENDDO
            cName = STRTRAN(cName, Chr(0), "")
     
            hAddress = hAddress - hBuffer  && decrease by initial offset
            cAddress = ""
            DO WHILE .T.
                ch = SUBSTR(cBuffer, hAddress, 2)
                IF ch = Chr(0)+Chr(0) Or hAddress > Len(cBuffer)
                    EXIT
                ENDIF
                cAddress = cAddress + ch
                hAddress = hAddress + 2
            ENDDO
            cAddress = STRTRAN(cAddress, Chr(0), "")
     
            INSERT INTO cs VALUES (cName, cAddress)
        ENDFOR
     
        = NetApiBufferFree(hBuffer)
     
        SELECT cs
        GO TOP
        BROWSE NORMAL NOWAIT
    * end of main
     
    PROCEDURE decl
     
        DECLARE INTEGER NetWkstaTransportEnum IN netapi32;
            STRING servername, LONG lvl, INTEGER @bufptr,;
            LONG prefmaxlen, LONG @entriesread,;
            LONG @totalentries, LONG resumehandle
     
        DECLARE INTEGER NetApiBufferFree IN netapi32 INTEGER Buffer
     
        DECLARE INTEGER NetApiBufferSize IN netapi32;
            INTEGER Buffer, INTEGER @ByteCount
     
        DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
            STRING @dst, INTEGER src, INTEGER bufsize
     
    FUNCTION buf2dword(lcBuffer)
    RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
        BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
        BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
        BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
     
     
     

    User rating: 10/10 (1 votes)
    Rate this code sample:
    • ~
    3423 bytes  
    Created: 2004-05-29 19:30:27  
    Modified: 2006-07-07 10:00:06  
    Visits in 7 days: 95  
    Listed functions:
    NetApiBufferFree
    NetApiBufferSize
    NetWkstaTransportEnum
    Printer friendly API declarations
    My comment:
    For those who want to improve their MAC address skills :) -- read Three ways to get your MAC address of Khalid Shaikh on the http://www.codeguru.com/.
    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.234.126.92)
    3.56 hrs.Example: 'Wininet last error description'
    8.32 hrs.Example: 'How to view system icons for the classes installed on the local machine'
    8.44 hrs.Example: 'Mapping and disconnecting network drives'
    11.36 hrs.
    18.75 hrs.Function: 'PostQuitMessage'
    Function group: 'Message and Message Queue'
    23.54 hrs.Function: 'waveOutGetNumDevs'
     Example: 'Retrieving graphic capabilities of default printer'
    1 day(s)Function: 'GetFullPathName'
    Function group: 'File Management'
     Function: 'GetWindowRect'
     Example: 'Placing On-screen Alert on top of all windows'
    Google
    Advertise here!