Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi CD Medien erkennen (https://www.delphipraxis.net/30772-cd-medien-erkennen.html)

burns4711 29. Sep 2004 08:50


CD Medien erkennen
 
Hallo,

hat jemand eine Ahnung wie man abfragen kann, welche Art von Medium gerade in ein CD Rom bzw. einen Brenner eingelegt ist,
(z.B. CD-R, CD-RW) und ob dieser schon beschrieben ist? Bin leider auf der Aspi Ebene nicht so bewandert.
Vielen Dank schonmal für Eure Hilfe.

static_cast 29. Sep 2004 08:58

Re: CD Medien erkennen
 
Hi,

ich hatte mal ein Projekt angefangen TISOLib, kannst ja mal auf der seite http://www.isolib.de oder http://sourceforge.net/projects/isolib/ schaun, da solltest du finden was du suchst.

Grüsse
Daniel

burns4711 29. Sep 2004 09:16

Re: CD Medien erkennen
 
Danke für die schnelle Antwort. Werde es mir anschauen.

static_cast 29. Sep 2004 09:27

Re: CD Medien erkennen
 
Ich habe dir das noch mal rauskopiert dann musst du dich da nicht durchwühlen:

Der Config Head:

Delphi-Quellcode:
type
  TDeviceConfigHeader = packed record
    DataLength       : Cardinal;
    Reserved         : Word;
    CurrentProfile   : Word;
    FeatureCode      : Word;
    Version          : Byte;
    AdditionalLength : Byte;
    OtherData        : Array[0..101] of Byte;
  end;
SPTI Command Structure:

Delphi-Quellcode:
type
  PSCSI_PASS_THROUGH = ^SCSI_PASS_THROUGH;
  SCSI_PASS_THROUGH = Record
    Length             : Word;
    ScsiStatus         : Byte;
    PathId             : Byte;
    TargetId           : Byte;
    Lun                : Byte;
    CdbLength          : Byte;
    SenseInfoLength    : Byte;
    DataIn             : Byte;
    DataTransferLength : ULONG;
    TimeOutValue       : ULONG;
    DataBufferOffset   : ULONG;
    SenseInfoOffset    : ULONG;
    Cdb                : Array[0..15] of Byte;
  end;

type
  PSCSI_PASS_THROUGH_DIRECT = ^SCSI_PASS_THROUGH_DIRECT;
  SCSI_PASS_THROUGH_DIRECT = record
    Length             : Word;
    ScsiStatus         : Byte;
    PathId             : Byte;
    TargetId           : Byte;
    Lun                : Byte;
    CdbLength          : Byte;
    SenseInfoLength    : Byte;
    DataIn             : Byte;
    DataTransferLength : ULONG;
    TimeOutValue       : ULONG;
    DataBuffer         : Pointer;
    SenseInfoOffset    : ULONG;
    Cdb                : Array[0..15] of Byte;
  end;

type
  PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER = ^SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER = record
    Spt     : SCSI_PASS_THROUGH_DIRECT;
    Filler  : ULONG;
    SenseBuf : Array[0..31] of Byte;
  end;
Laufwerk öffnen / schließen:

Delphi-Quellcode:
function OpenDrive(Const ADrive: Char): THandle;
begin
  Result := CreateFile( PChar('\\.\'+ ADrive +':'),
                        GENERIC_READ Or GENERIC_WRITE,
                        FILE_SHARE_READ Or FILE_SHARE_WRITE,
                        Nil,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        0);
end;

function CloseDrive(Const AHandle: THandle):Boolean;
begin
  Result := CloseHandle(AHandle);
end;

Die Funktion selber:

Delphi-Quellcode:
function GetDiscType(const AHandle:THandle):Integer;
var
  SPTDW : SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  Size, Returned : LongWord;
  DeviceConfigHeader : TDeviceConfigHeader;
begin
  Result := -1;

  ZeroMemory(@SPTDW, SizeOf(SPTDW));
  Size := SizeOf(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);

  SPTDW.Spt.Length            := SizeOf(SCSI_PASS_THROUGH);
  SPTDW.Spt.CdbLength         := 10;
  SPTDW.Spt.SenseInfoLength   := 32;
  SPTDW.Spt.DataIn            := 1; //SCSI_IOCTL_DATA_IN;
  SPTDW.Spt.DataTransferLength := SizeOf(DeviceConfigHeader);
  SPTDW.Spt.TimeOutValue      := 120;
  SPTDW.Spt.DataBuffer        := @DeviceConfigHeader;
  SPTDW.Spt.SenseInfoOffset   := 48;

  SPTDW.Spt.Cdb[0] := $46;
  SPTDW.Spt.Cdb[1] := $02;
  SPTDW.Spt.Cdb[3] := $00;
  SPTDW.Spt.Cdb[7] := HiByte(SizeOf(DeviceConfigHeader));
  SPTDW.Spt.Cdb[8] := LoByte(SizeOf(DeviceConfigHeader));
(*
  if DeviceIoControl( AHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
                      @SPTDW, Size, @SPTDW, Size, Returned, Nil) then
*)
  if DeviceIoControl( AHandle, $4D014, @SPTDW, Size, @SPTDW, Size, Returned, Nil) then
  begin
    case ((( DeviceConfigHeader.CurrentProfile shl 8) and $FF00) or
          (( DeviceConfigHeader.CurrentProfile shr 8) and $00FF)) of
      $0000 : Result := 0;
      $0001 : Result := 1;
      $0002 : Result := 2;
      $0003 : Result := 3;
      $0004 : Result := 4;
      $0005 : Result := 5;
      $0008 : Result := 6;
      $0009 : Result := 7;
      $000A : Result := 8;
      $0010 : Result := 9;
      $0011 : Result := 10;
      $0012 : Result := 11;
      $0013 : Result := 12;
      $0014 : Result := 13;
      $001A : Result := 14;
      $001B : Result := 15;
      $0020 : Result := 16;
      $0021 : Result := 17;
      $0022 : Result := 18;
      $FFFF : Result := 19;
    else
      Result := -1;
    end;
  end;
end;
Und hier zu guter letzt die Disctypes:

Delphi-Quellcode:
const
  DiscTypes : Array [0..19] of String = ('No Current Profile',
                                         'Non Removable Disk',
                                         'Removable Disk',
                                         'Magneto Optical Erasable',
                                         'Optical Write Once',
                                         'AS-MO',
                                         'CD-ROM',
                                         'CD-R',
                                         'CD-RW',
                                         'DVD-ROM',
                                         'DVD-R SequentialRecording,',
                                         'DVD-RAM',
                                         'DVD-RW Restricted Overwrite',
                                         'DVD-RW Sequential Recording',
                                         'DVD+RW',
                                         'DVD+R',
                                         'DDCD-ROM',
                                         'DDCD-R',
                                         'DDCD-RW',
                                         'UNKNOWN');
Hoffe du kannst was mit anfangen =)

Grüsse
Daniel

//edit hatte noch (mehr) was vergessen, jetzt ist es aber komplett, sry! jetzt aber ;)

burns4711 29. Sep 2004 10:15

Re: CD Medien erkennen
 
Vielen Dank für deine Mühe hast mir echt weiter geholfen. Werde es nachher sofort einbauen in mein Programm.

static_cast 29. Sep 2004 10:33

Re: CD Medien erkennen
 
Kein Problem! =)

Solltest du noch Fragen oder Probs haben einfach posten!

Kernel32.DLL 30. Sep 2004 10:27

Re: CD Medien erkennen
 
Zitat:

ich hatte mal ein Projekt angefangen, TISOLib
Das heißt, es wird nicht mehr weiterentwickelt? Schade.

static_cast 30. Sep 2004 10:43

Re: CD Medien erkennen
 
Zitat:

Zitat von Kernel32.DLL
Zitat:

ich hatte mal ein Projekt angefangen, TISOLib
Das heißt, es wird nicht mehr weiterentwickelt? Schade.

Doch schon wenn ich mal wieder Zeit habe (Urlaub oder so) *g* oder ich mal weite leute finde die mich noch unterstützen wollen/können.

Kernel32.DLL 30. Sep 2004 11:09

Re: CD Medien erkennen
 
Ah, ok :zwinker:

Ach, ne' Frage hätte ich noch:

Wo hab ihr die Infos über SPTI her? Ich hab mich nämlich fast totgesucht!

static_cast 30. Sep 2004 11:16

Re: CD Medien erkennen
 
Was genau meinst du? Wie man es anspricht? Ist alles im Windows DDK zu finden.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:49 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz