Autor Beitrag
Lucky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84

XP
Delphi 7
BeitragVerfasst: Di 06.05.08 15:54 
Hi,
brauch mal wieder eure hilfe...versuch grad ein programm zu programmieren das mir einen usb-stick immer den selben laufwerksbuchstaben zuweist...habe mit hilfe des internets untigen quellcode zamgebastelt allerdings funktioniert es leider net...seht ihr nen fehler? schon mal vielen dank chris

ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
function TForm1.pfadbuchstabezuweisen(Ziellwb:string; namedesusblaufwerk:string):boolean;
type
  tmountname = function(ziellwb:string; volumename:string; buffer:dword):boolean;stdcall;
  taction    = function(ziellwb:string; volumename:string):boolean;stdcall;
var
  dlllibrary     : THandle;
  setvolumemountpoint : taction;
  volumename : array[0..1000] of char;
  getvolumenamemountpoint : tmountname;
begin
  result := false;
  result := DefineDosDevice(DDD_RAW_TARGET_PATH,pchar(ziellwb),pchar(namedesusblaufwerk));
  dlllibrary      := LoadLibrary('Kernel32.dll');
  @getvolumenamemountpoint := GetProcAddress(dlllibrary,'GetVolumeNameForVolumeMountPointA');
  if @getvolumenamemountpoint <> nil then
  begin
    Result := getvolumenamemountpoint(Ziellwb,volumename,MAX_PATH);
    if (not getvolumenamemountpoint(pchar(Ziellwb),volumename,MAX_PATH)) then
      volumename[0] := #0;

    result := DefineDosDevice(DDD_RAW_TARGET_PATH or DDD_EXACT_MATCH_ON_REMOVE or DDD_EXACT_MATCH_ON_REMOVE,pchar(ziellwb),pchar(namedesusblaufwerk) );
  end;

  @SetVolumeMountPoint := GetProcAddress(dlllibrary,'SetVolumeMountPointA');
  setvolumemountpoint(Pchar(Ziellwb),volumename);

  if @setvolumemountpoint <> nil then
    result := setvolumemountpoint(Pchar(Ziellwb),volumename);

  FreeLibrary(dlllibrary);
end;
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 06.05.08 23:54 
Was genau funktioniert denn nicht?
Und abgesehen davon: wenn ich meinen USB-Stick anstecke (egal an welchem USB-Port) bekommt er immer den selben Laufwerksbuchstaben zugewiesen :?

AXMD
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: Mi 07.05.08 01:41 
user profile iconLucky hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
type
  tmountname = function(ziellwb:string; volumename:string; buffer:dword):boolean;stdcall;
  taction    = function(ziellwb:string; volumename:string):boolean;stdcall;
Diese Definitionen sind mit Sicherheit nicht korrekt. Die Windows API benutzt nicht den Typ String sondern PChar, PAnsiChar, usw.
Die korrekte Definition steht in der Dokumentation:
msdn.microsoft.com/e...aa364994(VS.85).aspx