Ir al contenido


Foto

Error al intentar obtener datos del disco duro


  • Por favor identifícate para responder
10 respuestas en este tema

#1 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 01 abril 2009 - 04:15

Hola

Estoy haciendo una ventana de Acerca de.... y dentro de esa ventana quiero poner algunos detalles sobre el espacio de disco duro.

Tengo este código:



delphi
  1. procedure TForm2.Button1Click(Sender: TObject);
  2. var
  3.   lpRoot: PChar;
  4.   lpFreeBytesToCaller,lpTotalBytes,lpFreeBytes: PLargeInteger;
  5.   int64Total,int64Free: Int64;
  6. begin
  7.     lpRoot := 'C:\';
  8.     if Windows.GetDiskFreeSpaceEx( lpRoot,
  9.                                     lpFreeBytesToCaller,
  10.                                     lpTotalBytes,
  11.                                     lpFreeBytes ) then begin
  12.         int64Total := int64(lpTotalBytes);
  13.         int64Free  := int64(lpFreeBytes);
  14.         Memo1.Lines.Add('Espacio Total del Disco: ' + Format('%d',[int64Total]));
  15.         Memo1.Lines.Add('Espacio Libre del Disco: ' +  Format('%d',[int64Free]));
  16.     end;
  17. end;



Pero me muestra el siguiente error:

---------------------------
Debugger Fault Notification
---------------------------
Project C:\Desarrollo\TDelphi\Comun\API MS\Project2.exe faulted with message: 'access violation at 0x00438aff: read of address 0x00000003'. Process Stopped. Use Step or Run to continue.
---------------------------
OK 
---------------------------


Debo comentar que además del error que me enví­a no me muestra los datos correctamente.

También usaba la función Windows.GetDiskFreeSpace la cual no me muestra ningún error sin embargo no me muestran tampoco los datos correctamente.



delphi
  1. function EspacioLibreEnDisco( const Drive : char ) : Int64;
  2. begin
  3.       lpRootPathName := PChar( Drive + ':\' );
  4.       if Windows.GetDiskFreeSpace( lpRootPathName,
  5.                                     lpSectorsPerCluster,
  6.                                     lpBytesPerSector,
  7.                                     lpNumberOfFreeClusters,
  8.                                     lpTotalNumberOfClusters ) then
  9.           Result := lpNumberOfFreeClusters * lpBytesPerSector * lpSectorsPerCluster
  10.       else
  11.           Result := -1;
  12. end;



¿Que estoy haciendo mal?

Salud OS
  • 0

#2 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 01 abril 2009 - 04:59

Prueba con esto amigo:



delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   freeSpace, totalSpace: Double;
  4.   s: Char;
  5. begin
  6.   // Drive letter
  7.   s := 'D';
  8.  
  9.   freeSpace  := DiskFree(Ord(s) - 64);
  10.   totalSpace := DiskSize(Ord(s) - 64);
  11.  
  12.   label1.Caption := Format('Espacio Disponible: %12.0n', [freeSpace]);
  13.   Label2.Caption := Format('Total de Espacio: %12.0n', [totalSpace]);
  14.   Label3.Caption := IntToStr(Round((totalSpace - freeSpace) / totalSpace * 100)) +
  15.     ' Porciento usado.';
  16. end;



Saludos.
  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 01 abril 2009 - 05:07

Gracias amigo enecumene, pues si, efectivamente si me muestra correctamente los datos, que estoy haciendo mal con el API :(

Salud OS
  • 0

#4 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 01 abril 2009 - 05:14

Ah qué bien te haya funcionado, pues de API ni idea :s, vamos a esperar a los maestros de esa area a ver qué dicen.

Saludos.
  • 0

#5 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 01 abril 2009 - 05:18

Ah qué bien te haya funcionado, pues de API ni idea :s, vamos a esperar a los maestros de esa area a ver qué dicen.

Saludos.


Yeap, aunque tu respuesta soluciona mi "problema" me gustarí­a saber que tan "wey" soy con el API :D

Salud OS
  • 0

#6 cHackAll

cHackAll

    Advanced Member

  • Administrador
  • 599 mensajes

Escrito 01 abril 2009 - 05:44



delphi
  1. // el compilador realiza "imul" a 32 bits
  2. // el casting obliga a llamar a "_llmul" a 64 bits
  3. function EspacioLibreEnDisco(const Drive: Char): Int64;
  4. var SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters: Cardinal;
  5. begin
  6. if Windows.GetDiskFreeSpace(PChar(Drive + ':\'), SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters) then
  7.   Result := BytesPerSector * SectorsPerCluster * Int64(NumberOfFreeClusters) // Int64()
  8. else
  9.   Result := -1;
  10. end;
  11.  
  12. // problema con puntero (ultimo parámetro)
  13. procedure TForm1.Button1Click(Sender: TObject);
  14. var FreeBytesToCaller, TotalBytes, FreeBytes: Int64;
  15. begin
  16. if Windows.GetDiskFreeSpaceEx('c:\', FreeBytesToCaller, TotalBytes, @FreeBytes) then
  17.   begin
  18.   Memo1.Lines.Add('Espacio Total del Disco: ' + Format('%u', [TotalBytes]));
  19.   Memo1.Lines.Add('Espacio Libre del Disco: ' +  Format('%u', [FreeBytesToCaller]));
  20.  
  21.   Memo1.Lines.Add('"EspacioLibreEnDisco": ' +  IntToStr(EspacioLibreEnDisco('c')));
  22.   end;
  23. end;


  • 0

#7 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 01 abril 2009 - 05:53

Vaya, esos pequeños detalles que hacen que una aplicación sea defectuosa.

Gracias little Bro :)

Salud OS
  • 0

#8 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 01 abril 2009 - 06:49

Hola

Gracias por la ayuda amigos, me he decidido por el uso del API GetDiskFreeSpaceEx.

Salud OS
  • 0

#9 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 02 abril 2009 - 11:01

Hola

Pues ya estoy agregando mas datos, utilizando la función GetSystemInfo() obtenemos el tipo de procesador.



delphi
  1. var
  2.   siSysInfo: SYSTEM_INFO;
  3.   pType: string;
  4.  
  5.   //Obtener Tipo de procesador
  6.   Windows.GetSystemInfo(siSysInfo);
  7.   case siSysInfo.dwProcessorType of
  8.      386  : pType := 'Intel® 386';
  9.      486  : pType := 'Intel® 486';
  10.      586  : pType := 'Intel® Pentium®';
  11.      2200 : pType := 'Intel® IA64';
  12.      8664 : pType := 'AMD® x8664';
  13.   end;
  14.   Label6.Caption := 'Procesador ' + pType;



Salud OS
  • 0

#10 AngelF

AngelF

    Advanced Member

  • Miembros
  • PipPipPip
  • 100 mensajes
  • LocationValencia - España

Escrito 26 mayo 2009 - 02:31

¿Y existe alguna función que nos dé el número de serie de un disco duro? Pero me refiero al número de serie que permanece inmutable aún cuando se formatee el disco.

Un saludo.
  • 0

#11 cHackAll

cHackAll

    Advanced Member

  • Administrador
  • 599 mensajes

Escrito 26 mayo 2009 - 03:07



delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3. hDevice, Dummy: Cardinal;
  4. Buffer: array [0..527] of Char;
  5. begin
  6. hDevice := _lopen('\\.\C:', OF_READWRITE);
  7. if hDevice <> INVALID_HANDLE_VALUE then
  8.   begin
  9.   DeviceIoControl(hDevice, $0007C088, PChar(#0#2#0#0#0#1#1#0#0#176#236#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0), 32, @Buffer, SizeOf(Buffer), Dummy, nil);
  10.   MessageBox(Handle, @Buffer[36], nil, MB_ICONINFORMATION); // 20 chars
  11.   CloseHandle(hDevice);
  12.   end;
  13. end;


  • 0




IP.Board spam blocked by CleanTalk.