Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to retrieve adapter information for the local computer (including MAC address)
Retrieving current settings for an ODBC connection
Retrieving the interface–to–IP address mapping table
Retrieving the User Datagram Protocol (UDP) listener table
Windows Shell Icons displayed and exported to ICO files (Vista)
How to register custom Event Log source
Round FoxPro form
Verifying a file using the Authenticode policy provider
Browsing Windows Known Folders (Special Folders)
Displaying the associated icons and descriptions for files and folders
GetProcessVersion points at target OS
How to retrieve information about a cache entry (Internet Explorer)
How to retrieve list of system DSNs (Data Source Name) with parameters
Starting a dialog box for connecting to network resources (mapping network drive)
Using the SetErrorMode for determining if a floppy drive is ready
Exporting DLL icon resources as .ICO files
How to retrieve number of objects in the Recycle Bin
Listing INF files in a specified directory
Winsock: reading and setting socket options
Displaying printer-properties Property Sheet for the specified printer
How to copy the image of a form to the Clipboard using Bitmap API functions
How to extract frames from AVI files
Retrieving country-specific dialing information from the Windows Telephony list of countries
The window and its ancestors
Enumerating printer drivers installed

User rating: 9/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
Versions:
click to open
Before you begin:

See also:
  • Enumerating locally installed printers
  • Enumerating the print processors and supporting data types installed on the specified server
  • Enumerating print jobs and retrieving information for default printer
  • How to retrieve number of print jobs that have been queued for the printer
  • Enumerating the ports that are available for printing on a specified server

  •  
    #DEFINE GMEM_FIXED 0
    DO declare
     
    *|typedef struct _DRIVER_INFO_2 { 
    *|  DWORD  cVersion;     0:4
    *|  LPTSTR pName;        4:4
    *|  LPTSTR pEnvironment; 8:4
    *|  LPTSTR pDriverPath;  12:4
    *|  LPTSTR pDataFile;    16:4
    *|  LPTSTR pConfigFile;  20:4
    *|} DRIVER_INFO_2, *PDRIVER_INFO_2; -> 24 bytes
     
    #DEFINE DRIVER_INFO_SIZE 24
     
    PRIVATE hBuffer, nBufsize, cBuffer, cInfo
     
    nBufsize = 16384
    hBuffer = GlobalAlloc(GMEM_FIXED, nBufsize)
     
    LOCAL lcServer, lnResult, lnReturned, lnCount
    STORE 0 TO lnReturned, lnIndex, lnCount
     
    * use Null for local computer or a valid server name 
    * e.g. "\\MYSERVER"
    lcServer = Null
    lnResult = EnumPrinterDrivers(lcServer,;
        Null, 2, hBuffer, nBufsize,;
        @lnReturned, @lnCount)
     
    IF lnResult = 0
        ? "Error code:", GetLastError()
        = GlobalFree(hBuffer)
        RETURN
    ENDIF
     
    cBuffer = REPLICATE(CHR(0), nBufsize)
    = Mem2Str(@cBuffer, hBuffer, nBufsize)
     
    * cursor for storing driver data
    CREATE CURSOR csDrvList (;
        ver I, drvname C(50),;
        envname C(20),;
        drvpath C(200),;
        drvfile C(200), cfgfile C(200))
     
    FOR lnIndex=0 TO lnCount-1
     
        cInfo = SUBSTR(cBuffer,;
            lnIndex * DRIVER_INFO_SIZE+1,;
            DRIVER_INFO_SIZE)
     
        INSERT INTO csDrvList;
        VALUES (mw(1), ms(5), ms(9),;
            ms(13), ms(17), ms(21))
     
    ENDFOR
     
    = GlobalFree(hBuffer)
     
    IF USED("csDrvList")
        GO TOP
        EDIT NORMAL NOWAIT
    ENDIF
    * end of main
     
    FUNCTION mw(lnOffs As Number)
    RETURN buf2dword(SUBSTR(cInfo, lnOffs, 4))
     
    FUNCTION ms(lnOffs As Number)
    RETURN GetMemStr(buf2dword(SUBSTR(cInfo, lnOffs, 4)))
     
    FUNCTION GetMemStr(lnAddr As Number)
        IF lnAddr = 0
            RETURN ""
        ENDIF
     
        LOCAL lnOffs, lcResult, ch
        lnOffs = lnAddr - hBuffer + 1
        lcResult = ""
     
        DO WHILE lnOffs < nBufsize
            ch = SUBSTR(cBuffer, lnOffs,1)
            IF ch = Chr(0)
                EXIT
            ELSE
                lcResult = lcResult + ch
            ENDIF
            lnOffs = lnOffs + 1
        ENDDO
    RETURN lcResult
     
    FUNCTION buf2dword (lcBuffer As Character)
    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)
     
    PROCEDURE declare
        DECLARE INTEGER EnumPrinterDrivers IN winspool.drv;
            STRING pName, STRING pEnvironment,;
            LONG Lvl, INTEGER pDrvInfo,;
            INTEGER cbBuf, INTEGER @pcbNeeded,;
            INTEGER @pcReturned
     
        DECLARE INTEGER GetLastError IN kernel32
        DECLARE INTEGER GlobalFree IN kernel32 INTEGER hMem
     
        DECLARE INTEGER GlobalAlloc IN kernel32;
            INTEGER wFlags, INTEGER dwBytes
     
        DECLARE RtlMoveMemory IN kernel32 As Mem2Str;
            STRING @Dest, INTEGER Src,;
            INTEGER nLength
     

    User rating: 9/10 (1 votes)
    Rate this code sample:
    • ~
    2587 bytes  
    Created: 2001-08-01 12:00:00  
    Modified: 2010-08-05 09:31:03  
    Visits in 7 days: 107  
    Listed functions:
    EnumPrinterDrivers
    GetLastError
    GlobalAlloc
    GlobalFree
    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 (72.44.48.122)
    1.52 hrs.Example: 'Switching between keyboard layouts'
     Function: 'JetRetrieveColumn'
    Function group: 'Extensible Storage Engine (ESE, Jet Blue)'
    4.6 hrs.Example: 'Get the power status of your laptop computer'
    4.61 hrs.Function: 'GdipDisposeImage'
    7.79 hrs.Function: 'LocalSize'
    8.13 hrs.Example: 'Displaying the main Dial-Up Networking dialog box'
     Example: 'How to create a desktop shortcut (shell link)'
    8.14 hrs.Example: 'Creating a directory on the FTP'
    8.26 hrs.Function: 'getservbyname'
     Function: 'NetMessageNameAdd'
    Function group: 'Network Management'
    Google
    Advertise here!