Back to the WFC main page

wfc_close_handle

$Revision: 10 $

Declaration

BOOL wfc_close_handle( HANDLE handle )

Description

This function returns TRUE if the handle was successfully closed using the CloseHandle() Win32 API.

Example

int _tmain( int number_of_command_line_arguments, LPCTSTR command_line_arguments[] )
{
   WFCTRACEINIT( TEXT( "_tmain()" ) );

   if ( number_of_command_line_arguments < 2 )
   {
      return( EXIT_SUCCESS );
   }

   TCHAR physical_disk[ MAX_PATH ];

   ZeroMemory( physical_disk, sizeof( physical_disk ) );

   _stprintf( physical_disk, TEXT( "\\\\.\\PHYSICALDRIVE%u" ), _ttoi( command_line_arguments[ 1 ] ) );

   HANDLE disk_handle = NULL;

   disk_handle = CreateFile( physical_disk,
                             GENERIC_READ | GENERIC_WRITE,
                             0,
                             0,
                             OPEN_EXISTING,
                             FILE_ATTRIBUTE_NORMAL,
                             NULL );

   if ( disk_handle != INVALID_HANDLE_VALUE )
   {
      DISK_GEOMETRY disk_geometry;

      ZeroMemory( &disk_geometry, sizeof( disk_geometry ) );

      DWORD number_of_bytes_read = 0;

      if ( DeviceIoControl( disk_handle,
                            IOCTL_DISK_GET_DRIVE_GEOMETRY,
                            NULL,
                            0,
                           &disk_geometry,
                            sizeof( disk_geometry ),
                           &number_of_bytes_read,
                            NULL ) != FALSE )
      {
         _tprintf( TEXT( "Number of Cylinders (low)     %lu\n" ), disk_geometry.Cylinders.LowPart  );
         _tprintf( TEXT( "Number of Cylinders (high)    %lu\n" ), disk_geometry.Cylinders.HighPart );
         _tprintf( TEXT( "Number of Tracks per Cylinder %lu\n" ), disk_geometry.TracksPerCylinder  );
         _tprintf( TEXT( "Number of Sectors per Track   %lu\n" ), disk_geometry.SectorsPerTrack    );
         _tprintf( TEXT( "Number of Bytes per Sector    %lu\n" ), disl_geometry.BytesPerSector     );
      }

      wfc_close_handle( disk_handle );
   }

   return( EXIT_SUCCESS );
}

API's Used

wfc_close_handle() uses the following API's:
Copyright, 2000, Samuel R. Blackburn
$Workfile: wfc_close_handle.cpp $
$Modtime: 1/17/00 9:31a $