Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom GDI+ class
Obtaining names and positions for shortcuts located on the Windows Desktop
Winsock: sending email messages (SMTP, port 25)
GDI+: Implementing image scrolling with inertia
Custom HttpRequest class (WinHTTP)
Splash Screen for the VFP application
Browsing Windows Known Folders (Special Folders)
Detecting changes in connections to removable drives (VFP9)
Displaying dimmed window behind VFP top-level form
Printing Image File, programmatically set print page orientation to landscape
Moving shortcut to a specified position on the Windows Desktop
Compressing and decompressing files with Windows API Runtime Library routines
Generating random cryptographic keys
Monitoring clipboard content changes (VFP9)
Placing On-screen Alert on top of all windows
Switching between keyboard layouts
How to enumerate logon sessions on local computer
Finding out if the current user is the Guest account
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Disconnecting USB Mass Storage Device programmatically
How to enable the SE_SHUTDOWN_NAME privilege for the application
How to find which fonts Windows uses for drawing captions, menus and message boxes
Pocket PC: custom RAPI class for operating with files and folders on mobile device
Custom FTP Class for Visual FoxPro application
Enumerating network interfaces on the local computer

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:

An output of C# version:


See also:
  • How to retrieve adapter information for the local computer
  • Retrieving the interface–to–IP address mapping table

  •  
    #DEFINE NO_ERROR 0
    DO declare
     
    LOCAL lnResult, lnIfCount, lnInfIndex
     
    * counting network interfaces on the local computer
    lnIfCount = 0
    lnResult = GetNumberOfInterfaces(@lnIfCount)
     
    IF lnResult <> NO_ERROR
        ? "Error code:", lnResult
    ENDIF
     
    CREATE CURSOR csResult (index N(3), adapttype C(20), mtu N(16),;
        addrlen N(2), bt0 N(3), bt1 N(3), bt2 N(3), bt3 N(3),;
        bt4 N(3), bt5 N(3), bt6 N(3), bt7 N(3), bps N(16),;
        admstat N(16), opstat C(20), outqlen N(16), descr C(200))
     
    FOR lnInfIndex=1 TO lnIfCount
        * retrieving information for the specified network interface
        = SaveIfEntry( m.lnInfIndex )
     
    ENDFOR
     
    SELECT csResult
    GO TOP
    BROWSE NORMAL NOWAIT
     
    PROCEDURE SaveIfEntry (lnIndex)
    #DEFINE MAX_INTERFACE_NAME_LEN  256
    #DEFINE MAXLEN_PHYSADDR 8
    #DEFINE MAXLEN_IFDESCR  256
     
    *| typedef struct _MIB_IFROW {
    *| WCHAR wszName[MAX_INTERFACE_NAME_LEN];                0:512
    *| DWORD dwIndex;    // index                          512:4
    *| DWORD dwType;     // type                           516:4
    *| DWORD dwMtu;      // max transmission unit          520:4
    *| DWORD dwSpeed;    // speed                          524:4
    *| DWORD dwPhysAddrLen;    // length of phys.address   528:4
    *| BYTE  bPhysAddr[MAXLEN_PHYSADDR];//adapt.phys.addr. 532:8
    *| DWORD dwAdminStatus;   // admin.status              540:4
    *| DWORD dwOperStatus;    // operational status        544:4
    *| DWORD dwLastChange;    // lasttime op.stat.chng     548:4
    *| DWORD dwInOctets;      // octets received           552:4
    *| DWORD dwInUcastPkts;   // unicast packets rcvd      556:4
    *| DWORD dwInNUcastPkts;  // non-unicast packets rcvd  560:4
    *| DWORD dwInDiscards;    // rcvd packets discarded    564:4
    *| DWORD dwInErrors;      // erroneous packets rcvd    568:4
    *| DWORD dwInUnknProtos;  // unkn.prot.packets rcvd    572:4
    *| DWORD dwOutOctets;     // octets sent               576:4
    *| DWORD dwOutUcastPkts;  // unicast packets sent      580:4
    *| DWORD dwOutNUcastPkts; // non-unicast packets sent  584:4
    *| DWORD dwOutDiscards;   // outg.packets discarded    588:4
    *| DWORD dwOutErrors;     // erroneous packets sent    592:4
    *| DWORD dwOutQLen;       // output queue length       596:4
    *| DWORD dwDescrLen;      // length of bDescr member   600:4
    *| BYTE  bDescr[MAXLEN_IFDESCR];  // interface descr   604:256
    *| } MIB_IFROW,*PMIB_IFROW; total bytes=860
    #DEFINE MIB_IFROW_SIZE  860
     
        LOCAL lcBuffer, lnResult, lnAdaptType, lnMtu, lnSpeedBps,;
            lnAdminStat, lnOpStatus, lnAddrLen, lnDescrLength,;
            lnOutQLen, lcDescr
     
        lcBuffer = Repli(Chr(0), MAX_INTERFACE_NAME_LEN*2) +;
            num2dword(lnIndex) +;
            Repli(Chr(0), MIB_IFROW_SIZE-4-MAX_INTERFACE_NAME_LEN*2)
     
        lnResult = GetIfEntry(@lcBuffer) 
        IF lnResult = NO_ERROR
            lnAdaptType = buf2dword(SUBSTR(lcBuffer, 517,4))
            lnMtu       = buf2dword(SUBSTR(lcBuffer, 521,4))
            lnAddrLen   = buf2dword(SUBSTR(lcBuffer, 529,4))
            lnSpeedBps  = buf2dword(SUBSTR(lcBuffer, 525,4))
            lnAdminStat = buf2dword(SUBSTR(lcBuffer, 541,4))
            lnOpStatus  = buf2dword(SUBSTR(lcBuffer, 545,4))
            lnOutQLen   = buf2dword(SUBSTR(lcBuffer, 597,4))
            lnDescrLen  = buf2dword(SUBSTR(lcBuffer, 601,4))
            lcDescr     = SUBSTR(lcBuffer, 605,lnDescrLen-1)
     
            INSERT INTO csResult VALUES (lnIndex,;
                GetAdapterType(lnAdaptType), lnMtu, lnAddrLen,;
                Asc(SUBSTR(lcBuffer, 533,1)),;
                Asc(SUBSTR(lcBuffer, 534,1)),;
                Asc(SUBSTR(lcBuffer, 535,1)),;
                Asc(SUBSTR(lcBuffer, 536,1)),;
                Asc(SUBSTR(lcBuffer, 537,1)),;
                Asc(SUBSTR(lcBuffer, 538,1)),;
                Asc(SUBSTR(lcBuffer, 539,1)),;
                Asc(SUBSTR(lcBuffer, 540,1)),;
                lnSpeedBps, lnAdminStat,;
                GetAdapterOpstatus(lnOpStatus),;
                lnOutQLen, lcDescr)
        ELSE
            ? "Error code:", lnResult
        ENDIF
    RETURN
     
    FUNCTION GetAdapterType (lnIndex)
    #DEFINE MIB_IF_TYPE_OTHER 1
    #DEFINE MIB_IF_TYPE_ETHERNET 6
    #DEFINE MIB_IF_TYPE_TOKENRING 9
    #DEFINE MIB_IF_TYPE_FDDI 15
    #DEFINE MIB_IF_TYPE_LOOPBACK 24
    #DEFINE MIB_IF_TYPE_PPP 23
    #DEFINE MIB_IF_TYPE_SLIP 28
        DO CASE
        CASE lnIndex = MIB_IF_TYPE_OTHER
            RETURN "Other"
        CASE lnIndex = MIB_IF_TYPE_ETHERNET
            RETURN "Ethernet"
        CASE lnIndex = MIB_IF_TYPE_TOKENRING
            RETURN "Token ring"
        CASE lnIndex = MIB_IF_TYPE_FDDI
            RETURN "FDDI"
        CASE lnIndex = MIB_IF_TYPE_LOOPBACK
            RETURN "Loopback"
        CASE lnIndex = MIB_IF_TYPE_PPP
            RETURN "PPP"
        CASE lnIndex = MIB_IF_TYPE_SLIP
            RETURN "SLIP"
        ENDCASE
    RETURN "Unknown type"
     
    FUNCTION GetAdapterOpstatus (lnIndex)
    #DEFINE MIB_IF_OPER_STATUS_NON_OPERATIONAL  0
    #DEFINE MIB_IF_OPER_STATUS_UNREACHABLE 1
    #DEFINE MIB_IF_OPER_STATUS_DISCONNECTED 2
    #DEFINE MIB_IF_OPER_STATUS_CONNECTING 3
    #DEFINE MIB_IF_OPER_STATUS_CONNECTED 4
    #DEFINE MIB_IF_OPER_STATUS_OPERATIONAL 5
        DO CASE
        CASE lnIndex=MIB_IF_OPER_STATUS_NON_OPERATIONAL
            RETURN "Non operational"
        CASE lnIndex=MIB_IF_OPER_STATUS_UNREACHABLE
            RETURN "Unreachable"
        CASE lnIndex=MIB_IF_OPER_STATUS_DISCONNECTED
            RETURN "Disconnected"
        CASE lnIndex=MIB_IF_OPER_STATUS_CONNECTING
            RETURN "Connecting"
        CASE lnIndex=MIB_IF_OPER_STATUS_CONNECTED
            RETURN "Connected"
        CASE lnIndex=MIB_IF_OPER_STATUS_OPERATIONAL
            RETURN "Operational"
        ENDCASE
     
    RETURN  "Unknown type"
     
    FUNCTION num2dword (lnValue) 
    #DEFINE m0       256
    #DEFINE m1     65536
    #DEFINE m2  16777216
        LOCAL b0, b1, b2, b3
        b3 = Int(lnValue/m2)
        b2 = Int((lnValue - b3 * m2)/m1)
        b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
        b0 = Mod(lnValue, m0)
    RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
     
    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 GetNumberOfInterfaces;
        IN iphlpapi INTEGER @pdwNumIf
     
        DECLARE INTEGER GetIfEntry;
        IN iphlpapi STRING @pIfRow
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    5811 bytes  
    Created: 2002-01-13 10:11:52  
    Modified: 2010-05-19 22:06:13  
    Visits in 7 days: 42  
    Listed functions:
    Printer friendly API declarations
    My comment:
    The GetInterfaceInfo function retrieves network interface information in one call. Though this data does not include information about the loopback interface.
    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-2016 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.34), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.205.43.70)
    3 sec.Function: 'JetEndSession'
    5 sec.Function: 'RtlGetCompressionWorkSpaceSize'
    7 sec.Function: 'IsChild'
    Function group: 'Window'
    10 sec.Example: 'Using FrameRgn for displaying system colors'
    13 sec.Function: 'NetUserGetGroups'
    Function group: 'Network Management'
    15 sec.Example: 'How to display Windows On-Screen Keyboard'
    Language: 'C#'
    18 sec.Function: 'JetSetColumn'
    Function group: 'Extensible Storage Engine (ESE, Jet Blue)'
    25 sec.Example: 'How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory'
    30 sec.Function: 'JetCommitTransaction'
    32 sec.Function: 'SetMonitorContrast'
    Google
    Advertise here!