Using Win32 functions in Visual FoxPro Image Gallery
Error Handling
..msdn
Beep
FatalAppExit
FlashWindow
FlashWindowEx
FormatMessage
GetErrorMode
GetLastError
MessageBeep
SetErrorMode
SetLastError
Code examples:
A class that encrypts and decrypts files using Cryptography API Functions
Adding printer to the list of supported printers for the specified server
Basic Volume information
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Closing Windows
Compressing and decompressing files with Windows API Runtime Library routines
Converting command-line string to a set of Unicode argument strings (WinNT only)
Converting long file names to the short format and vice versa
Converting Unicode data from the Clipboard to a character string using a given code page
Copying files as a transacted operation (Vista)
Creating a console window for Visual FoxPro application
Creating a device context for the specified printer
Creating a folder
Creating a mailslot
CryptoAPI: Collection of Providers class
Custom FTP Class for Visual FoxPro application
Custom HttpRequest class (WinHTTP)
Custom HttpRequest class (WinINet)
Determining if an Active Network Connection is Available
DiskFreeSpace class
Displaying bitmap using the AlphaBlend function
Displaying dimmed window behind VFP top-level form
Encapsulating access to the Windows Services in a class
Enumerating forms supported by a specified printer
Enumerating ports that are available for printing on a specified server
Enumerating print jobs and retrieving information for default printer (JOB_INFO_1 structures)
Enumerating print processors and supporting data types installed on the specified server
Enumerating printer drivers installed
Enumerating Processes -- WinNT
Enumerating the subkeys of a user-specific key
Finding parameters for the region specified
GetFileOwner - Get the owner of an NTFS file
Getting a bit more than the _CLIPTEXT offers
How to access a file using not its name but an alias (hard link)
How to adjust monitor brightness (Vista, monitor with DDC support)
How to block the ALT+TAB shortcut (WinXP)
How to block the PrintScreen key
How to create a service object
How to create MD-5 and SHA-1 hash values from a string
How to delete a service object
How to delete all print jobs for a printer
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
How to display a user-defined icon in the MessageBox dialog
How to display the port-configuration dialog box for a port on the specified server
How to display the Properties dialog box for a file (ShellExecuteEx)
How to download this reference`s archive through WinInet functions using InternetOpenUrl
How to enable the SE_SHUTDOWN_NAME privilege for the application
How to enumerate cookies and URL History entries in the cache of the local computer
How to enumerate sessions and processes on a specified terminal server
How to enumerate terminal servers within the specified Windows domain
How to extract frames from AVI files
How to fill a buffer with random bytes using Cryptography API Functions
How to find the application associated with a file name
How to find when the application started
How to find which fonts Windows uses for drawing captions, menus and message boxes
How to initiate System shutdown
How to make application automatically close all documents it opened
How to ping a remote site using IP Helper API calls
How to play AVI file on the _screen
How to prevent users from accessing the Windows Desktop and from switching to other applications
How to retrieve configuration data for a specified printer stored in the registry (PrinterDriverData key)
How to retrieve information about a cache entry (Internet Explorer)
How to retrieve the number of print jobs queued for the printer
How to retrieve version information for the specified file
How to run FoxPro application under different user name (impersonating user)
How to save registry key including its subkeys and values to a file
How to set Creation Date/Time for a folder (WinNT)
How to Start a Process as Another User (NT/XP/2K)
How to test file attributes (key method for FileExists and DirectoryExists routines)
How to write and read Window Properties for the specified window
HOWTO: Use the Win32 API to Access File Dates and Times
Locking and unlocking file of a VFP table
Locking the workstation
Monitoring changes occurring within a directory
Obtaining I/O counts for the current process
Obtaining physical parameters for a drive: sectors, clusters, cylinders...
Peer-to-peer LAN messenger built with Mailslot API functions
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Printing Image File, programmatically set print page orientation to landscape
Reading and setting system access privileges for the current process
Reading current hardware profile
Reading entries from Event logs
Reading security permissions for NTFS files and folders
Reading the structure of VFP main menu
Removing FTP directory
Retrieveing information about the active window (even if it is not owned by the calling process)
Retrieving a handle to DLL and address of an exported function in it
Retrieving graphic capabilities of default printer
Retrieving local computer and user names
Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)
Retrieving the System Time adjustment
Scanning a hierarchy of child windows down from the Windows Desktop
Setting the date and time that a file was created
Setting the last-error code for the FoxPro
Setting the volume label
Setting the Window Region for a form
Simple printer queue monitor: deletes, pauses, resumes print jobs for local printer
Start an executable from VFP application by using the CreateProcess
Starting external program from VFP and waiting for its termination
Storing registration key in the resources of an executable file
Testing serial ports
The DetectAutoProxyUrl function identifies the auto-config script location
Using Change Notification Objects to monitor changes to the printer or print server
Using EnumPrinters function to enumerate locally installed printers
Using File Mapping for enumerating files opened by Visual FoxPro
Using FtpCommand
Using LoadLibrary
Using named pipes for interprocess communication
Using shared memory to exchange data between two FoxPro applications
Using the CreateFile
Using the NetMessageBufferSend to send messages on the network
Using the Semaphore object
Using the Semaphore object to allow only one instance of VFP application running
Validating the heap of the calling process
Wininet last error description
Winsock: retrieving information from a host database for a given host name
Writing entries to custom Event Log
Obtaining physical parameters for a drive: sectors, clusters, cylinders...

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:
The code shows how to obtain number of cylinders, tracks, sectors and clusters for a given device like HD, floppy or CD.

See also:
  • Displaying the drive type value
  • Basic Volume information
  • Setting the volume label
  • Disk in drive A:
  •  
    DO decl
    DO GetDeviceInfo_1
    DO GetDeviceInfo_2
    * end of main
     
    PROCEDURE GetDeviceInfo_1
        STORE 0 TO nSectorsPerCluster, nBytesPerSector,;
            nFreeClusters, nTotalClusters
     
        LOCAL lcRootName, nTotalSize
        lcRootName = "C:\"
        *lcRootName = "A:\"  && a way to test if a disk inserted
     
        = GetDiskFreeSpace(lcRootName, @nSectorsPerCluster,;
            @nBytesPerSector, @nFreeClusters, @nTotalClusters)
     
        ?
        ? "*** Returned by GetDiskFreeSpace:"
        ? "Device name:", lcRootName
        ? "Total clusters:", nTotalClusters
        ? "Free clusters:", nFreeClusters
        ? "Sectors per cluster:", nSectorsPerCluster
        ? "Bytes per sector:", nBytesPerSector
     
        nTotalSize = nTotalClusters * nSectorsPerCluster * nBytesPerSector
        ? "Total size: ", TRANSFORM(nTotalSize, "999,999,999,999")
     
    PROCEDURE GetDeviceInfo_2
    #DEFINE FILE_SHARE_READ   1
    #DEFINE FILE_SHARE_WRITE  2
    #DEFINE OPEN_EXISTING     3
    #DEFINE INVALID_HANDLE_VALUE -1
    #DEFINE IOCTL_DISK_GET_DRIVE_GEOMETRY 0x70000
    #DEFINE ERROR_INSUFFICIENT_BUFFER 122
    #DEFINE MAX_DWORD 0x100000000
     
        LOCAL cDrive, hDevice
        cDrive = "\\.\PhysicalDrive0"
    *    cDrive = "\\.\c:"
     
        hDevice = CreateFile(m.cDrive, 0,;
            BITOR(FILE_SHARE_READ, FILE_SHARE_WRITE),;
            0, OPEN_EXISTING, 0, 0)
     
        IF hDevice = INVALID_HANDLE_VALUE
            ? "Error: INVALID_HANDLE_VALUE"
            RETURN
        ENDIF
     
    *|typedef struct _DISK_GEOMETRY {
    *|  LARGE_INTEGER Cylinders;  0:8
    *|  MEDIA_TYPE MediaType;     8:4
    *|  DWORD TracksPerCylinder; 12:4
    *|  DWORD SectorsPerTrack;   16:4
    *|  DWORD BytesPerSector;    20:4
    *|} DISK_GEOMETRY; total bytes: 24
    #DEFINE DISK_GEOMETRY_SIZE 24
     
        LOCAL cBuffer, nBufsize, nCylinders, nMediaType, nTracksPerCyl,;
            nSecPerTrack, nBytesPerSec, nTotalSize
        cBuffer = REPLICATE(CHR(0), DISK_GEOMETRY_SIZE)
        nBufsize=0
     
        = DeviceIoControl(m.hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY,;
            Null, 0, @cBuffer, LEN(cBuffer), @nBufsize, 0)
     
        nCylinders = GetLongInt(SUBSTR(cBuffer,1,4), SUBSTR(cBuffer,5,4))
        nMediaType = buf2dword(SUBSTR(cBuffer,9,4))
        nTracksPerCyl = buf2dword(SUBSTR(cBuffer,13,4))
        nSecPerTrack =  buf2dword(SUBSTR(cBuffer,17,4))
        nBytesPerSec = buf2dword(SUBSTR(cBuffer,21,4))
        ?
        ? "*** Returned by DeviceIoControl:"
        ? "Device name:", cDrive
        ? "Cylinders:", nCylinders
        ? "Media Type:", nMediaType
        ? "Tracks per cylinder:", nTracksPerCyl
        ? "Sector per track:", nSecPerTrack
        ? "Bytes per sector:", nBytesPerSec
     
        nTotalSize = nCylinders * nTracksPerCyl * nSecPerTrack *;
            nBytesPerSec
        ? "Total size:", TRANSFORM(nTotalSize, "999,999,999,999")
     
        = CloseHandle(hDevice)
     
    PROCEDURE decl
        DECLARE INTEGER GetDiskFreeSpace IN kernel32;
            STRING lpRootPathName, INTEGER @lpSectorsPerCluster,;
            INTEGER @lpBytesPerSector, INTEGER @lpNumberOfFreeClusters,;
            INTEGER @lpTotalNumberOfClusters
     
        DECLARE INTEGER DeviceIoControl IN kernel32;
            INTEGER hDevice, INTEGER dwIoControlCode, STRING @lpInBuffer,;
            INTEGER nInBufferSize, STRING @lpOutBuffer, INTEGER nOutBufferSize,;
            INTEGER @lpBytesReturned, INTEGER lpOverlapped
     
        DECLARE INTEGER CreateFile IN kernel32;
            STRING lpFileName, INTEGER dwAccess, INTEGER dwShareMode,;
            INTEGER lpSecurityAttr, INTEGER dwCreationDisp,;
            INTEGER dwFlagsAndAttr, INTEGER hTemplateFile
     
        DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
        DECLARE INTEGER GetLastError IN kernel32
     
    FUNCTION GetLongInt(Lo, Hi)
    #DEFINE MAX_DWORD 0x100000000
        IF VARTYPE(m.Lo)="C"
            Lo = buf2dword(m.Lo)
        ENDIF
        IF VARTYPE(m.Hi) = "C"
            Hi = buf2dword(m.Hi)
        ENDIF
    RETURN m.Hi * MAX_DWORD + m.Lo
     
    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:
    • ~
    3753 bytes  
    Created: 2001-08-13 12:00:00  
    Modified: 2009-02-04 14:22:45  
    Visits in 7 days: 100  
    Listed functions:
    CloseHandle
    CreateFile
    DeviceIoControl
    GetDiskFreeSpace
    GetLastError
    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:
    sridhar | 2007-02-09 06:27:54
    Is it possible to get the serial number of the drive with DeviceIoControl ?

    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 (50.17.109.248)
    21.57 min.
    Function group: 'Data Decompression Library'
    21.62 min.Example: 'Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)'
    1.63 hrs.Example: 'How to find when the application started'
     Example: 'Reading entries from Event logs'
    11.99 hrs.Function: 'ReleaseMutex'
     Example: 'Adding user-defined items to the Control Menu of VFP form (requires VFP9)'
    12.55 hrs.Function: 'GetUserNameEx'
    Function group: 'System Information'
     Example: 'How to remove a directory that is not empty'
     Example: 'How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory'
    15.19 hrs.Example: 'Using InternetGoOnline function'
    Google
    Advertise here!