|
On Windows NT, an application can use the DeviceIoControl function to perform direct input and output operations on, or retrieve
information about, a floppy disk drive, hard disk drive, tape drive, or CD-ROM drive.
The following example demonstrates how to retrieve information about the first
physical drive in the system. It uses the CreateFile function to obtain the device handle of the first physical drive, and then
uses the DeviceIoControl function with the IOCTL_DISK_GET_DRIVE_GEOMETRY control code to fill a DISK_GEOMETRY structure with information about the drive.
BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice;
BOOL fResult;
DWORD cb;
hDevice = CreateFile("\\\\.\\PhysicalDrive0",
0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == NULL)
return FALSE;
fResult = DeviceIoControl(hDevice,
IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
pdg, sizeof(*pdg), &cb, (LPOVERLAPPED) NULL);
if (!fResult)
return FALSE;
CloseHandle(hDevice);
}
This example succeeds only when it runs on Windows NT, for two reasons:
- The standard device input/output control codes are available only on Windows
NT, and
- On Windows 95, an application must specify a virtual device driver in the CreateFile function
not a specific device.
Related Links
Software for Delphi and C++ Builder developers
Software for Visual Studio .NET developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET
TMS Scripter Studio Pro components for Delphi/C++Builder
More Online Helps
Win32 Multimedia Programmer's Reference (mmedia.hlp)
OLE Programmer's Reference (ole.hlp)
Microsoft Windows Pen API Programmer's Reference (penapi.hlp)
Microsoft Windows Sockets 2 Reference (sock2.hlp)
Microsoft Windows Telephony API (TAPI) Programmer's Reference (tapi.hlp)
Unix Manual Pages
|