Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to retrieve the number of print jobs queued for the printer
The original LoadPicture() function in VFP returns valid handles to bitmaps, icons, cursors, and metafiles
Using Change Notification Objects to monitor changes to the printer or print server
Storing screen shot of a form to bitmap file
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Disabling mouse and keyboard input for the main VFP window (with the app still running)
Locking and unlocking file of a VFP table
How to create MD-5 and SHA-1 hash values from a string
Retrieving configuration information for the specified server (Win2000/XP)
Creating a mailslot
How to set Creation Date/Time for a folder (WinNT)
WAV file player
How to register custom Event Log source
HOWTO: Use the Win32 API to Access File Dates and Times
Adding user-defined items to the Control Menu of VFP form (requires VFP9)
Extensible Storage Engine class library
Getting a bit more than the _CLIPTEXT offers
How to retrieve network parameters for the local computer (including Host name, Domain name, and DNS Server)
Pocket PC: custom RAPI class for operating with files and folders on mobile device
Retrieving names for the registered clipboard formats
Storing content of the Clipboard to a bitmap file
Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)
Using the FindMediaType function
Adding a background image to VFP report (VFP9, ReportListener)
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: 110  
    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 (54.234.126.92)
    2.14 hrs.Example: 'Converting strings between ANSI and OEM'
    10.72 hrs.Example: 'Setting the date and time that a file was created'
     Example: 'Reading the state of mouse buttons within DO WHILE loop'
     Example: 'Using NetWkstaTransportEnum to obtain MAC Address of remote server'
    14.27 hrs.Example: 'Wininet last error description'
    19.04 hrs.Example: 'How to view system icons for the classes installed on the local machine'
    19.16 hrs.Example: 'Mapping and disconnecting network drives'
    22.08 hrs.
    1 day(s)Function: 'PostQuitMessage'
    Function group: 'Message and Message Queue'
     Function: 'waveOutGetNumDevs'
    Google
    Advertise here!