Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
GDI+: retrieving list of available image encoders and image decoders
How to release and renew a lease on an IP address previously obtained through Dynamic Host Configuration Protocol (DHCP)
Playing WAV sounds simultaneously
Reading metrics for the currently selected font
Retrieving graphic capabilities of your display
URL: converting unsafe characters and spaces into escape sequences
FindText -- the hopeless and useless Common Dialog
How to find which fonts Windows uses for drawing captions, menus and message boxes
How to perform Base64 encoding/decoding using Cryptography API Functions
How to view icons stored in executable files (Icon Viewer) - II
How to view system icons for the classes installed on the local machine
Obtaining a handle to the desktop associated with the calling thread
Using the IsWindowEnabled function
Creating a directory on the FTP
Enumerating print processors and supporting data types installed on the specified server
Enumerating the subkeys for a given registry key
Removing FTP directory
Retrieving the command line for the VFP session
Using the CopyFile
Using the Semaphore object to allow only one instance of VFP application running
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
GDI+: printing vertical text on VFP reports via generated images (VFP9)
How to build UDP responder
How to control Adobe Reader 9.0 (SDI mode) from VFP application
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: 171  
    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 (72.44.48.122)
    1.18 hrs.Example: 'GDI+: Storing content of the Clipboard to a bitmap file'
    1.19 hrs.Function: 'GetClipboardOwner'
    3.3 hrs.Function: 'IsWindow'
    Function group: 'Window'
    7.19 hrs.Example: 'Displaying system dialog that selects a folder'
     Function: 'GdipFillPieI'
    8.22 hrs.Function: 'SetBkMode'
    Function group: 'Painting and Drawing'
     Example: 'A procedure for setting file times'
    8.23 hrs.Function: 'SQLExecDirect'
    Function group: 'ODBC API'
    10.77 hrs.Function: 'GdipTranslateMatrix'
     Function: 'WTSSendMessage'
    Google
    Advertise here!