Avatar billede danielhep Nybegynder
04. september 2002 - 13:09 Der er 3 kommentarer og
1 løsning

Formatere

Hey

Jeg vil godt lave et program som kan formatere disketter, og drev i c++.

Er der nogle som kender nogle gode links, som virker og ikke er på tysk??

Mvh

Daniel
Avatar billede soepro Nybegynder
04. september 2002 - 13:55 #1
Hvorfor lave noget der findes i forvejen !?!

Du kan aktivere Windows egen format via:

#include <stdlib.h>

int main(void)
{
  system("format a:");
  return 0;
}

Windows har en API der kan formattere en diskette (eller en anden removable disk) - følgende er fra Win32 SDK Reference:

he DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the specified operation.

BOOL DeviceIoControl(

    HANDLE hDevice,    // handle to device of interest
    DWORD dwIoControlCode,    // control code of operation to perform
    LPVOID lpInBuffer,    // pointer to buffer to supply input data
    DWORD nInBufferSize,    // size of input buffer
    LPVOID lpOutBuffer,    // pointer to buffer to receive output data
    DWORD nOutBufferSize,    // size of output buffer
    LPDWORD lpBytesReturned,    // pointer to variable to receive output byte count
    LPOVERLAPPED lpOverlapped     // pointer to overlapped structure for asynchronous operation
  );   


Parameters

hDevice

Handle to the device that is to perform the operation. Call the CreateFile function to obtain a device handle.

dwIoControlCode

Specifies the control code for the operation. This value identifies the specific operation to be performed and the type of device on which the operation is to be performed. The following values are defined:

Value    Meaning
FSCTL_DISMOUNT_VOLUME    Dismounts a volume.
FSCTL_GET_COMPRESSION    Obtains the compression state of a file or directory
FSCTL_LOCK_VOLUME    Locks a volume.
FSCTL_READ_COMPRESSION    Reserved for future use.
FSCTL_SET_COMPRESSION    Sets the compression state of a file or directory.
FSCTL_UNLOCK_VOLUME    Unlocks a volume.
FSCTL_WRITE_COMPRESSION    Reserved for future use.
IOCTL_DISK_CHECK_VERIFY    Obsolete. Use IOCTL_STORAGE_CHECK_VERIFY
IOCTL_DISK_EJECT_MEDIA    Obsolete. Use IOCTL_STORAGE_EJECT_MEDIA
IOCTL_DISK_FORMAT_TRACKS    Formats a contiguous set of disk tracks.
IOCTL_DISK_GET_DRIVE_GEOMETRY    Obtains information on the physical disk's geometry.
IOCTL_DISK_GET_DRIVE_LAYOUT    Provides information about each partition on a disk.
IOCTL_DISK_GET_MEDIA_TYPES    Obsolete. Use IOCTL_STORAGE_GET_MEDIA_TYPES
IOCTL_DISK_GET_PARTITION_INFO    Obtains disk partition information.
IOCTL_DISK_LOAD_MEDIA    Obsolete. Use IOCTL_STORAGE_LOAD_MEDIA
IOCTL_DISK_MEDIA_REMOVAL    Obsolete. Use IOCTL_STORAGE_MEDIA_REMOVAL
IOCTL_DISK_PERFORMANCE    Provides disk performance information.
IOCTL_DISK_REASSIGN_BLOCKS    Maps disk blocks to spare-block pool.
IOCTL_DISK_SET_DRIVE_LAYOUT    Partitions a disk.
IOCTL_DISK_SET_PARTITION_INFO    Sets the disk partition type.
IOCTL_DISK_VERIFY    Performs logical format of a disk extent.
IOCTL_SERIAL_LSRMST_INSERT    Enables or disables placement of a line and modem status data into the data stream.
IOCTL_STORAGE_CHECK_VERIFY    Checks for change in a removable-media device.
IOCTL_STORAGE_EJECT_MEDIA    Ejects media from a SCSI device.
IOCTL_STORAGE_GET_MEDIA_TYPES    Obtains information about media support.
IOCTL_STORAGE_LOAD_MEDIA    Loads media into a device.
IOCTL_STORAGE_MEDIA_REMOVAL    Enables or disables the media eject mechanism.


For more detailed information on each control code, see its topic. In particular, each topic provides details on the usage of the lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, and lpBytesReturned parameters.

lpInBuffer

Pointer to a buffer that contains the data required to perform the operation.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not require input data.

nInBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpInBuffer.

lpOutBuffer

Pointer to a buffer that receives the operation's output data.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.

nOutBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpOutBuffer.

lpBytesReturned

Pointer to a variable that receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer.
If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation produces no output data, and lpOutBuffer can be NULL, the DeviceIoControl function makes use of the variable pointed to by lpBytesReturned. After such an operation, the value of the variable is without meaning.
If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this is an overlapped operation, you can get the number of bytes returned by calling GetOverlappedResult. If hDevice is associated with an I/O completion port, you can get the number of bytes returned by calling GetQueuedCompletionStatus.

lpOverlapped

Pointer to an OVERLAPPED structure.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, this parameter must point to a valid OVERLAPPED structure. In this case, DeviceIoControl is performed as an overlapped (asynchronous) operation. If the device was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function fails in unpredictable ways.
If hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag, this parameter is ignored and the DeviceIoControl function does not return until the operation has been completed, or an error occurs.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

If hDevice was opened with FILE_FLAG_OVERLAPPED and the lpOverlapped parameter points to an OVERLAPPED structure, DeviceIoControl is performed as an overlapped (asynchronous) operation. In this case, the OVERLAPPED structure must contain a handle to a manual-reset event object created by a call to the CreateEvent function. For more information on manual-reset event objects, see Synchronization.
If the overlapped operation cannot be completed immediately, the function returns FALSE, and GetLastError returns ERROR_IO_PENDING, indicating that the operation is executing in the background. When this happens, the operating system sets the event object in the OVERLAPPED structure to the nonsignaled state before DeviceIoControl returns. The system then sets the event object to the signaled state when the operation has been completed. The calling thread can use any of the wait functions to wait for the event object to be signaled, and then use the GetOverlappedResult function to determine the results of the operation. The GetOverlappedResult function reports the success or failure of the operation and the number of bytes returned in the lpOutBuffer buffer.

See Also

CreateEvent, CreateFile, GetOverlappedResult, GetQueuedCompletionStatus, OVERLAPPED
Avatar billede danielhep Nybegynder
04. september 2002 - 14:06 #2
Hvorfor ikke??

system("format a:");

Ja den virker sikkert ok, men det er ikke lige den kommando som jeg søger..
Jeg sidder med et WIn32 program, hvor jeg har en processbar,som indikere hvor langt formateringen er nået.
Så hvis du kan se hvad jeg mener, så er den der system("format a:"); til dos, og der popper et dos windiu frem.
Avatar billede soepro Nybegynder
04. september 2002 - 14:07 #3
Fandt også lige dette:

#include <windows.h>
#include <stdio.h>
#include <winioctl.h>

DISK_GEOMETRY SupportedGeometry[20];
DWORD SupportedGeometryCount;

VOID
GetSupportedGeometrys( HANDLE hDisk )

{
  DWORD ReturnedByteCount;

  if( DeviceIoControl(
          hDisk,
          IOCTL_DISK_GET_MEDIA_TYPES,
          NULL,
          0,
          SupportedGeometry,
          sizeof(SupportedGeometry),
          &ReturnedByteCount,
          NULL
      ))
      SupportedGeometryCount = ReturnedByteCount /  sizeof(DISK_GEOMETRY);

  else SupportedGeometryCount = 0;
}

VOID
PrintGeometry( PDISK_GEOMETRY lpGeometry )
{
  LPSTR MediaType;

  switch ( lpGeometry->MediaType ) {

      case F5_1Pt2_512:
        MediaType = "5.25, 1.2MB,  512 bytes/sector";
        break;
      case F3_1Pt44_512:
        MediaType = "3.5,  1.44MB, 512 bytes/sector";
        break;
      case F3_2Pt88_512:
        MediaType = "3.5,  2.88MB, 512 bytes/sector";
        break;
      case F3_20Pt8_512:
        MediaType = "3.5,  20.8MB, 512  bytes/sector";
        break;
      case F3_720_512:
        MediaType = "3.5,  720KB,  512 bytes/sector";

        break;
      case F5_360_512:
        MediaType = "5.25, 360KB,  512 bytes/sector";
        break;
      case F5_320_512:
        MediaType = "5.25, 320KB,  512 bytes/sector";
        break;
      case F5_320_1024:
        MediaType = "5.25, 320KB,  1024 bytes/sector";
        break;
      case F5_180_512:
        MediaType = "5.25, 180KB,  512 bytes/sector";
        break;
      case F5_160_512:
        MediaType = "5.25, 160KB,  512  bytes/sector";

        break;
      case RemovableMedia:
        MediaType = "Removable media other than floppy";
        break;
      case FixedMedia:
        MediaType = "Fixed hard disk media";
        break;
      default:
        MediaType = "Unknown";
        break;
  }
  printf("    Media Type %s\n", MediaType );
  printf("    Cylinders %d, Tracks/Cylinder %d, Sectors/Track %d\n",
          lpGeometry->Cylinders.LowPart, lpGeometry->TracksPerCylinder,
          lpGeometry->SectorsPerTrack

        );
}

void main( int argc, char *argv[], char *envp[] )
{
  HANDLE hDrive;
  UINT i;

  hDrive = CreateFile(
                  "\\\\.\\a:",
                  0,
                  FILE_SHARE_READ,
                  NULL,
                  OPEN_ALWAYS,
                  0,
                  NULL
                  );
  if ( hDrive == INVALID_HANDLE_VALUE )
  {
      printf( "Open failed: %d\n", GetLastError() );
      ExitProcess(1);

  }

  GetSupportedGeometrys( hDrive );

  printf( "\nDrive A supports the following disk geometries\n" );
  for( i=0; i<SupportedGeometryCount; i++ )
  {
      printf("\n");
      PrintGeometry( &SupportedGeometry[i] );
  }
  printf("\n");
}
Avatar billede danielhep Nybegynder
05. september 2002 - 01:01 #4
ok...det ser sku ok ud....
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester