Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Was passiert hier? (https://www.delphipraxis.net/1953-passiert-hier.html)

Christian Seehase 30. Nov 2003 12:44

Re: Was passiert hier?
 
Moin Lefko,

Zitat:

Zitat von Lefko
Ich hab Showmessage(GetEnvironmentVariable(COMPUTERNAME)) geschrieben; auch dieser string ist '', also leer.

Da Du das gar nicht compiliert bekommst, kannst Du auch keinen Leersting erhalten. ;-)

Schau Dir doch mal die Dokumentation zu den Funktionen an.
Könnte helfen ;-)

Lefko 30. Nov 2003 12:52

Re: Was passiert hier?
 
Hi Seehase,

lol, doch, geht kompiliert! Aber COMPUTERNAME ist dabei das leere result aus der function von Luckie lol, hab ich n bockmist geschrieben :D

zu GetEnvironmentVariable steht aber:

Zitat:

GetEnvironmentVariable(Name: string): string;

Description
GetEnvironmentVariable returns the value of the Windows environment variable indicated by Name.
Wie ist denn der Name dieser Variablen? Hab keine Ahnung von allem, was um Delphi herum passiert...

oder meinst du das hier:

Zitat:

The GetEnvironmentVariable function retrieves the value of the specified variable from the environment block of the calling process. The value is in the form of a null-terminated string of characters.

DWORD GetEnvironmentVariable(

LPCTSTR lpName, // address of environment variable name
LPTSTR lpBuffer, // address of buffer for variable value
DWORD nSize // size of buffer, in characters
);


Parameters

lpName
Points to a null-terminated string that specifies the environment variable.

lpBuffer


Points to a buffer to receive the value of the specified environment variable.

nSize

Specifies the size, in characters, of the buffer pointed to by the lpBuffer parameter.



Return Values


If the function succeeds, the return value is the number of characters stored into the buffer pointed to by lpBuffer, not including the terminating null character.
If the specified environment variable name was not found in the environment block for the current process, the return value is zero.
If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer size, in characters, required to hold the value string and its terminating null character.
Wenn ja, bitte erklär mir das kurz, ich kann mit 'Buffer' und 'address' und sowas nicht viel anfangen...

MfG Lefko.

Christian Seehase 30. Nov 2003 15:04

Re: Was passiert hier?
 
Moin Lefko,

ich meinte die API Funktion ;-)
Die Kapselung kennt D5 nicht.


Probier das hier mal aus.

Delphi-Quellcode:
var
  pBuf : PChar;
  dwLen : DWORD;

begin
  // Mit Hilfe der Funktion die erforderliche Buffergrösse ermitteln
  pBuf := nil;
  dwLen := 0;
  dwLen := GetEnvironmentVariable('COMPUTERNAME',pBuf,dwLen);
  inc(dwLen);
  // und dann erst auslesen
  pBuf := AllocMem(dwLen);
  try
    if GetEnvironmentVariable('COMPUTERNAME',pBuf,dwLen) = 0 then begin
      ShowMessage(SysErrorMessage(GetLastError));
    end else begin
      ShowMessage(trim(pBuf));
    end;
  finally
    FreeMem(pBuf,dwLen);
  end;
end;
Wie in C üblich gibt die Funktion ihren Rückgabewert in einen Speicherbereich aus, den man als Pointer (in diesem Falle Pointer auf Character) übergibt, und der vorher in der erforderlichen Grösse reserviert werden muss. (Netxxx Funktionen unter NT sind hier eine Ausnahme).

Lefko 30. Nov 2003 18:58

Re: Was passiert hier?
 
Allet klar, danke für das Beispiel!

Ich werd das morgen ausprobieren, hab jetzt keine Zeit.

BTW: Ich hab mir das gedacht, um - wie gesagt - einen PC zu identifizieren.

Gibbet nicht auch noch andere/einfachere/bessere Möglichkeiten, dies zu tun?

Hab was gelesen mit "MAC Adresse auslesen" aber das geht ja nur, wenn man ne Netzwerkkarte hat, was ja nicht jeder tut.


MfG Lefko.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:28 Uhr.
Seite 2 von 2     12   

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