AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Welche ist die aktuell gültige API um Systempfade zu bekomme?
Thema durchsuchen
Ansicht
Themen-Optionen

Welche ist die aktuell gültige API um Systempfade zu bekomme?

Ein Thema von Bernhard Geyer · begonnen am 22. Feb 2019 · letzter Beitrag vom 25. Feb 2019
Antwort Antwort
Seite 1 von 2  1 2      
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#1

Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 22. Feb 2019, 16:18
SHGetSpecialFolderLocation
Zitat:
SHGetSpecialFolderLocation is not supported and may be altered or unavailable in the future. Instead, use SHGetFolderLocation.
SHGetFolderLocation
Zitat:
Deprecated. Retrieves the path of a folder as an ITEMIDLIST structure.
Häää

Könnte es ShGetKnownFolderPath sein?
Da steht noch nicht "Deprecated" ...
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.345 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 22. Feb 2019, 16:33
Ja, Known Folders sind der aktuelle Weg. Hier steht meines Wissens auch noch keine Änderung an.
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!
  Mit Zitat antworten Zitat
Pfaffe

Registriert seit: 29. Jan 2009
294 Beiträge
 
Delphi 12 Athens
 
#3

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 22. Feb 2019, 18:28
Alternative: TPath, z.b. TPath.GetDocumentsPath für Windows wird dann im Quellcode von System.IOUtils SHGetFolderPath aufgerufen.
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 22. Feb 2019, 20:34
Alternative: TPath, z.b. TPath.GetDocumentsPath für Windows wird dann im Quellcode von System.IOUtils SHGetFolderPath aufgerufen.
SHGetFolderPath
Zitat:
Deprecated. Gets the path of a folder identified by a CSIDL value.
Also haben wir schon 3 abgekündigte Methoden für das gleiche Ziel
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
Schokohase
(Gast)

n/a Beiträge
 
#5

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 22. Feb 2019, 21:33
Es kommt darauf an, welche Betriebssysteme du noch unterstützen musst.

Ist noch etwas vor Windows Vista dabei, dann musst du bei SHGetFolderPath bleiben.
Ab Windows Vista und neuer kannst du komplett auf SHGetKnownFolderPath setzen.
  Mit Zitat antworten Zitat
Benutzerbild von GPRSNerd
GPRSNerd

Registriert seit: 30. Dez 2004
Ort: Ruhrpott
239 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 23. Feb 2019, 16:59
Da gibts schon was:

https://www.delphipraxis.net/135471-...olderpath.html
Stefan
  Mit Zitat antworten Zitat
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
2.824 Beiträge
 
Delphi 12 Athens
 
#7

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 24. Feb 2019, 08:03
Was spricht denn gegen die TPath.GetXXXX Methoden?

Sind in IOUtils drin und funktionieren soweit es diese Pfade jeweils gibt auch Cross Plattform.
Im jeweiligen Hilfetext steht auch jeweis drin, auf welches Verzeichnis unter welcher Plattform
das normalerweise verweist.

Also wozu das Rad neu erfinden bzw. zu plattform spezifisch in deinem Code werden?
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#8

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 24. Feb 2019, 09:08
Würde ich gerne machen.

Ich brauch (in zwei Fällen) CSIDL_PROFILE bzw. FOLDERID_Profile.
D.h. der "Rootpfad" des Profiles (i.d.R. c:\Users\<UserName>)

Und das ist (soweit ich bei TPath sehe) nicht abgebildet.
Also brauch ich eine eigene Methode mit der ich nur mit Delphi-Strings arbeite und den API-Aufruf kapsele.

Und ja. Ich weiß das man normalerweise die Anwendungsdaten nicht direkt im Profil-Hauptverzeichnis (bzw. direkt dort ein Verzeichnis) ablegt.
Wurde aber gemacht (ähnlich wie es z.B. IDEA oder Adobe Cloud)
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
Schokohase
(Gast)

n/a Beiträge
 
#9

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 24. Feb 2019, 11:29
Ich lasse mich da gerne von .Net inspirieren*

System.Environment.GetFolderPath (referencesource)

und dann käme ich z.B. auf
Delphi-Quellcode:
interface

{$SCOPEDENUMS ON}

const
  CSIDL_FLAG_CREATE = $8000;
  CSIDL_FLAG_DONT_VERIFY = $4000;
  CSIDL_ADMINTOOLS = $0030;
  CSIDL_PROFILE = $0028;

type
  TEnvironment = record
  public type
    TSpecialFolder = ( //
      AdminTools = CSIDL_ADMINTOOLS, //
      UserProfile = CSIDL_PROFILE);
    TSpecialFolderOption = ( //
      None = 0, //
      Create = CSIDL_FLAG_CREATE, //
      DoNotVerify = CSIDL_FLAG_DONT_VERIFY);
  private
    class function InternalGetFolder(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string; static;
  public
    class function GetFolderPath(AFolder: TSpecialFolder): string; overload; static;
    class function GetFolderPath(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string; overload; static;
  end;

implementation

uses
  Winapi.Windows,
  Winapi.SHFolder;

{ TEnvironment }

class function TEnvironment.GetFolderPath(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string;
begin
  Result := InternalGetFolder(AFolder, AOption);
end;

class function TEnvironment.InternalGetFolder(AFolder: TSpecialFolder; AOption: TSpecialFolderOption): string;
var
  LStr: array [0 .. MAX_PATH] of Char;
begin
  SetLastError(ERROR_SUCCESS);

  if SHGetFolderPath(0, Integer(AFolder) or Integer(AOption), 0, 0, @LStr) = S_OK then
    Result := LStr;
end;

class function TEnvironment.GetFolderPath(AFolder: TSpecialFolder): string;
begin
  Result := InternalGetFolder(AFolder, TSpecialFolderOption.None);
end;
Und der Aufruf ist sehr sprechend: TEnvironment.GetFolderPath(TEnvironment.TSpecialFolder.UserProfile); .

Und um auf wirklich alle SpecialFolder zuzugreifen muss man nur etwas Fleißarbeit investieren und TEnvironment.TSpecialFolder komplettieren.

* Was ich auch nicht verwerflich finden, gerade weil Emba das auch sehr gerne macht, allerdings hat man das Gefühl, dass die dabei meistens schielen.

Geändert von Schokohase (24. Feb 2019 um 11:33 Uhr)
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#10

AW: Welche ist die aktuell gültige API um Systempfade zu bekomme?

  Alt 24. Feb 2019, 11:38
Keine Ahnung was du uns mitteilen willst.
Aber warum das Rad neu erfinden es hat sich bzgl. der Frage in der API auch und besonders in Win10 nichts geändert.

Die Header bzw. der Aufruf von SHGetKnownFolderPath ist bestimmt schon seit D2009 seitens Emba in Delphi integriert und tut seine Arbeit.

just my 2 Cent.
Es ist nicht von Nöten dafür extra eine eigene Classe zu entwerfen.
Aber wie du willst.

gruss
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:26 Uhr.
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