AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi [Unicode/NT] Argumente eines Programms holen ...
Thema durchsuchen
Ansicht
Themen-Optionen

[Unicode/NT] Argumente eines Programms holen ...

Ein Thema von himitsu · begonnen am 9. Aug 2005 · letzter Beitrag vom 11. Sep 2005
Thema geschlossen
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.152 Beiträge
 
Delphi 12 Athens
 
#1

[Unicode/NT] Argumente eines Programms holen ...

  Alt 9. Aug 2005, 18:59
zu Beitrag "Argumente eines Programms holen ..."


Zitat von Assarbad:
Leider ist diese Variante nur mit ANSI-Longstrings möglich ... Unicode ... keine Spur :-/
Erstens sind in Delphi aus historischen Gründen viele Funktionen/Prozeduren nur als Ansi-Varianten und einige sogar nur in SingleByte-Ausführung vorhanden.
Und dann steht auch noch vollgendes im Win32 SDK.
Zitat von Microsoft Win32 Software Development Kit:
Non-Unicode console processes written in C can use the argc and argv arguments to access the command-line arguments. The parameters of the command-line string, excluding the program name, are also available to such non-Unicode applications as a parameter of the WinMain function. The reason for the Unicode exclusion from these options is that WinMain, argc, and argv use the LPSTR data type for parameters, not the LPTSTR datatype.

So, nun muß ich wohl auch noch meine Version vorstellen -.-''
Delphi-Quellcode:
Function _ParamCount: LongInt;
Function ParamStrA(Index: LongInt): AnsiString;
Function ParamStrW(Index: LongInt): WideString;
Delphi-Quellcode:
// © 1997-2005 by FNS Enterprize's™
// 2003-2005 by himitsu @ Delphi-PRAXiS

  Function _ParamCount: LongInt;
    Var P: PAnsiChar;
      B: Boolean;

    Begin
      Result := 0;
      P := GetCommandLineA;
      If P <> nil Then Dec(Result) Else Exit;
      While P^ <> #0 do Begin
        While (P^ <> #0) and (P^ <= ' ') do Inc(P);
        B := False;
        If P^ <> #0 Then Inc(Result);
        While (P^ <> #0) and ((P^ > ' ') or B) do Begin
          If P^ = '"Then B := not B;
          Inc(P);
        End;
      End;
    End;

  Function ParamStrA(Index: LongInt): AnsiString;
    Var P, P2: PAnsiChar;
      i: Integer;
      B: Boolean;

    Begin
      If Index = 0 Then Begin
        SetLength(Result, MaxPath);
        SetLength(Result, GetModuleFileNameA(0, Pointer(Result), MaxPath));
        Exit;
      End Else If Index < 0 Then Inc(Index);
      P := GetCommandLineA;
      If P <> nil Then
        While P^ <> #0 do Begin
          While (P^ <> #0) and (P^ <= ' ') do Inc(P);
          P2 := P; i := 0; B := False;
          While (P2^ <> #0) and ((P2^ > ' ') or B) do Begin
            If P2^ <> '"Then Inc(i) Else B := not B;
            Inc(P2);
          End;
          If (Index = 0) and (P <> P2) Then Begin
            SetLength(Result, i);
            i := 1;
            Repeat
              If P^ <> '"Then Begin Result[i] := P^; Inc(i); End;
              Inc(P);
            Until P >= P2;
            Exit;
          End;
          P := P2;
          Dec(Index);
        End;
      Result := '';
    End;

  Function ParamStrW(Index: LongInt): WideString;
    Var P, P2: PWideChar;
      i: Integer;
      B: Boolean;

    Begin
      If Index = 0 Then Begin
        SetLength(Result, MaxPath);
        SetLength(Result, GetModuleFileNameW(0, Pointer(Result), MaxPath));
        Exit;
      End Else If Index < 0 Then Inc(Index);
      P := GetCommandLineW;
      If P <> nil Then
        While P^ <> #0 do Begin
          While (P^ <> #0) and (P^ <= ' ') do Inc(P);
          P2 := P; i := 0; B := False;
          While (P2^ <> #0) and ((P2^ > ' ') or B) do Begin
            If P2^ <> '"Then Inc(i) Else B := not B;
            Inc(P2);
          End;
          If (Index = 0) and (P <> P2) Then Begin
            SetLength(Result, i);
            i := 1;
            Repeat
              If P^ <> '"Then Begin Result[i] := P^; Inc(i); End;
              Inc(P);
            Until P >= P2;
            Exit;
          End;
          P := P2;
          Dec(Index);
        End;
      Result := '';
    End;

Und hier noch die weiteren Funktionsdefinitionen, falls diese fehlen sollten.
Allerdings kann man diese vermutlich schon in der Windows-Unis von Delphi finden.
Delphi-Quellcode:
Const Kernel = 'kernel32.dll';

Function GetModuleFileNameA(Module: THandle; Buffer: PAnsiChar; BufferSize: LongInt): LongInt; StdCall;
  External Kernel Name 'GetModuleFileNameA';
Function GetModuleFileNameW(Module: THandle; Buffer: PWideChar; BufferSize: LongInt): LongInt; StdCall;
  External Kernel Name 'GetModuleFileNameW';
Function GetCommandLineA: PAnsiChar; StdCall; External Kernel Name 'GetCommandLineA';
Function GetCommandLineW: PWideChar; StdCall; External Kernel Name 'GetCommandLineW';

Natürlich auch in himi's Hier im Forum suchenUCC enthalten. (FNSEnt.-.FILES = FNS_Files.pas)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
 
Olli
(Gast)

n/a Beiträge
 
#2

Re: [Unicode/NT] Argumente eines Programms holen ...

  Alt 24. Aug 2005, 15:58
Zitat von himitsu:
Zitat von Assarbad:
Leider ist diese Variante nur mit ANSI-Longstrings möglich ... Unicode ... keine Spur :-/
Das Zitat ist nicht ganz vollständig, da ich mich auf ParamStr() und ParamCount bezog ...
Zitat von Assarbad:
als Delphianer lehnt man sich ja oft zurück und benutzt mal eben ParamCount und ParamStr(x). Leider ist diese Variante nur mit ANSI-Longstrings möglich ... Unicode ... keine Spur :-/
Zitat von himitsu:
Erstens sind in Delphi aus historischen Gründen viele Funktionen/Prozeduren nur als Ansi-Varianten und einige sogar nur in SingleByte-Ausführung vorhanden.
Historisch würde ich die nicht gerade nennen, mangels Präprozessor ist die zwittrige Auslegung für Unicode und ANSI unter Delphi einfach äußerst schlecht machbar (sehen wir aktuell wieder in JEDI-APIlib). Entweder man nimmt das eine oder das andere :-\

Die Funktionen sind übrigens gut gelungen
 
11. Sep 2005, 12:29
Dieses Thema wurde von "Chakotay1308" von "Neuen Beitrag zur Code-Library hinzufügen" nach "Windows API / MS.NET Framework API" verschoben.
Befindet sich nun hier in der Code-Library.
Thema geschlossen


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 00:59 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