Autor Beitrag
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 22.10.06 13:16 
Also folgendes Problem: ich will die Festplattenbezeichnung herausfinden. Ich meine die festplattenbezeichnung die in der eckigen klammer in der DriveCombobox steht. das Problem nur: Ich hab keine DriveCombobox auf meinem Form und will auch keine dort haben. mit der Procedure
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
// Name des LW
function TForm1.getlwname : string;
var dummy: DWORD;
    buffer: array[0..MAX_PATH] of Char;
begin
  try
    GetVolumeInformation(PChar(self.LW),
      buffer,
      SizeOf(buffer),
      nil,
      dummy,
      dummy,
      nil,
      0);
    Result := StrPas(buffer);
  except
    result := 'Unbekannt';
  end;
end;

zeigt er unbekannt an obwohl die C:\ platte in der DriveCombobox den Namen "Windows" hat.

lg el

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 22.10.06 13:38 
Hallo,

versuch mal:
Zeile: 8 = @buffer[0],
Zeile: 15 = Result := buffer;

self.LW muss die komplette Laufwerksangabe enthalten > 'C:\'

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
elundril Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 22.10.06 13:50 
ne funzt leider nicht!

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 22.10.06 14:17 
Der Fehler dürfte daher rühren, dass du als letzten Parameter 0 übergibst. Im PSDK steht in der Dokumentation zu dem Befehl aber, dass dies die Größenangabe für einen Namenspuffer ist...
Und wenn du sagst, dass in deinen Buffer nur 0 Byte reinpassen, nun ja, was soll Windows da denn schon reinbekommen in 0 Byte...

Das hier ist aus Scriba, dort habe ich es für CD-Laufwerke benutzt, deshalb die aktuelle Bezeichnung der Funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function TCDUtils_XP.GetCDDriveName(Lw: Char): String;
//Gibt die Bezeichnung des Laufwerks zurück
const
  volumeNameSize: Cardinal = 50;
  filesystemNameSize: Cardinal = 50;
var
  volumeNameBuf: PChar;
  serialNumber: PDWord;
  maxCPLength: DWord;
  filesystemFlags: DWord;
  filesystemName: PChar;
begin
  volumeNameBuf := StrAlloc(volumeNameSize);
  filesystemName := StrAlloc(filesystemNameSize);
  serialNumber := nil;

  if GetVolumeInformation(
    PChar(Lw + ':\'), volumeNameBuf, volumeNameSize, serialNumber,
    maxCPLength, filesystemFlags, filesystemName, filesystemNameSize) then
    Result := volumeNameBuf
  else
    Result := '';
end;

Dem Programmierstil nach zu urteilen stammt diese Funktion nicht von mir, das sieht etwas seltsam aus, aber woher der Code ist, weiß ich nicht mehr. Funktionieren sollte es jedenfalls.
elundril Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 23.10.06 11:08 
thx an alle!

funktioniert eh! der Code von Lannes. es war nur so das ich in einer VM programmiere und dort meine Festplatten keinen namen haben!

lg mike

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 23.10.06 12:38 
Hallo,

es funktionieren alle Codes, auch Deiner. :wink:

@jaenicke
bei Deinem Code fehlt die Freigabe (StrDispose) des durch StrAlloc reservierten Speichers.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )