Using Win32 functions in Visual FoxPro Image Gallery
File Management
..msdn
CopyFile
CopyFileTransacted
CreateDirectory
CreateFile
CreateFileTransacted
CreateHardLink
CreateSymbolicLink
DeleteFile
DeleteFileTransacted
FindClose
FindCloseChangeNotification
FindFirstChangeNotification
FindFirstFile
FindNextChangeNotification
FindNextFile
FlushFileBuffers
GetBinaryType
GetCurrentDirectory
GetDriveType
GetFileAttributes
GetFileAttributesEx
GetFileInformationByHandle
GetFileType
GetFullPathName
GetLongPathName
GetShortPathName
GetTempFileName
GetTempPath
LockFile
MoveFile
MoveFileTransacted
OpenFile
QueryDosDevice
ReadDirectoryChangesW
ReadFile
RemoveDirectory
RemoveDirectoryTransacted
ReplaceFile
SearchPath
SetCurrentDirectory
SetEndOfFile
SetFileAttributes
SetFilePointer
SetFilePointerEx
SetSearchPathMode
UnlockFile
WriteFile
_lclose
_lopen
Code examples:
Creating a file, then moving it to another destination
How to convert a bitmap file to monochrome format (1 bpp)
How to set Creation Date/Time for a folder (WinNT)
HOWTO: Use the Win32 API to Access File Dates and Times
Monitoring changes occurring within a directory
Obtaining physical parameters for a drive: sectors, clusters, cylinders...
Peer-to-peer LAN messenger built with Mailslot API functions
Storing content of the Clipboard to a bitmap file
Storing screen shot of a form to bitmap file
Subclassing CommandButton control to create BackColor property
Testing serial ports
Using InternetSetFilePointer when resuming interrupted download from the Internet
Using mailslots to send messages on the network
Using named pipes for interprocess communication
Using the CreateFile
Using the DeleteFile
Vertical Label control
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: 53  
    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.19.155.235)
    4 sec.Example: 'Extensible Storage Engine class library'
    2.43 hrs.Example: 'Using MessageBeep'
    Google
    Advertise here!