Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
How to change display settings: screen resolution, screen refresh rate
GDI+: Storing content of the Clipboard to a bitmap file
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Winsock: sending email messages (SMTP, port 25)
Printing Image File, programmatically set print page orientation to landscape
How to convert a bitmap file to monochrome format (1 bpp)
HOWTO: Use the Win32 API to Access File Dates and Times
How to print FoxPro form
How to print a bitmap file
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Mapping and disconnecting network drives
How to put a horizontal text scrolling on the form (a news line, marquee)
Using WM_COPYDATA for interprocess communication (VFP9)
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Custom HttpRequest class (WinHTTP)
Using EnumPrinters function to enumerate locally installed printers
Windows Shell Icons displayed and exported to ICO files (Vista)
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Placing On-screen Alert on top of all windows
Custom HttpRequest class (WinINet)
Custom FTP Class for Visual FoxPro application
How to set Creation Date/Time for a folder (WinNT)
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: 84  
    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-2014 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.68), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.196.207.55)
    5 sec.Example: 'Opening the Page Setup dialog box to specify the attributes of a printed page'
    5 day(s)Function: 'Escape'
    Function group: 'Printing and Print Spooler'
     Function: 'RtlCompressBuffer'
     Function: 'inet_ntoa'
     Function: 'CryptDestroyKey'
    Function group: 'Cryptography Reference'
    Google
    Advertise here!