Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi GetWindowModuleFileName gibt nichts zurück (https://www.delphipraxis.net/34348-getwindowmodulefilename-gibt-nichts-zurueck.html)

c113plpbr 21. Nov 2004 17:36


GetWindowModuleFileName gibt nichts zurück
 
Ich versuche per GetWindowModuleFileName den Namen (& Pfad) eines Programms über das FensterHandle herauszufinden, doch leider gibt die Funktion nichts zurück.
Mein Code sieht in etwa so aus:
Delphi-Quellcode:
var
  hWnd_ : HWND;
  fname : PAnsiChar;
begin
  fname := nil;
  hWnd_ := FindWindow('Notepad', nil);
  if(hWnd_ = 0)then
  begin
    Application.MessageBox('FindWindow failed!', '', 0);
    exit;
  end;

  GetWindowModuleFileNameA(hWnd_, fname, MAX_PATH);

  Application.MessageBox(fname, 'fname', 0);
end;
Die "fname"-Message bleib immer leer. Weis jemand woran das liegt?

ciao & thx, Philipp

Dax 21. Nov 2004 17:40

Re: GetWindowModuleFileName gibt nichts zurück
 
So msollte es gehen:
Delphi-Quellcode:
var
  hWnd_ : HWND;
  fname : PAnsiChar;
begin
  GetMem(fname, MAX_PATH);
  hWnd_ := FindWindow('Notepad', nil);
  if(hWnd_ = 0)then
  begin
    Application.MessageBox('FindWindow failed!', '', 0);
    exit;
  end;

  GetWindowModuleFileNameA(hWnd_, fname, MAX_PATH);

  Application.MessageBox(fname, 'fname', 0);
end;

c113plpbr 21. Nov 2004 17:43

Re: GetWindowModuleFileName gibt nichts zurück
 
@Dax: Das hab ich auch schon probiert, leider erfolglos.

jim_raynor 21. Nov 2004 18:08

Re: GetWindowModuleFileName gibt nichts zurück
 
Versuche fName als Array[0..MAX_PATH] of Char zu deklarieren.

c113plpbr 21. Nov 2004 18:11

Re: GetWindowModuleFileName gibt nichts zurück
 
@jim_raynor: Hab ich auch schon probiert, funktioniert leider auch nicht. :(

jim_raynor 21. Nov 2004 18:14

Re: GetWindowModuleFileName gibt nichts zurück
 
Dann prüfe doch mal mit GetLastError den Fehlercode, den dir Windows zurück gibt.

c113plpbr 21. Nov 2004 18:19

Re: GetWindowModuleFileName gibt nichts zurück
 
Zitat:

Zitat von jim_raynor
Dann prüfe doch mal mit GetLastError den Fehlercode, den dir Windows zurück gibt.

Der ist ganz ordnungsgemäß 0 ...
Kann das mal jemand bei sich testen? Geht das allgemein nicht, liegt es an meinem rechner, oder is da irgendwas anderes faul?

Luckie 21. Nov 2004 18:49

Re: GetWindowModuleFileName gibt nichts zurück
 
Der Klssen name vom Notepad ist wahrscheinlich nicht "Notepad":
Delphi-Quellcode:
hWnd_ := FindWindow('Notepad', nil);
Als Handle wirst du dann eben null zurückbekommen. Guck doch erstmal, ob diu da ein gültiges Handle bekommst. Desweiteren würde ich den Vorschlag mit GetLastError nicht so einfach abtun, wer weiß, was eventuell noch shcief geht. :roll:

c113plpbr 21. Nov 2004 19:13

Re: GetWindowModuleFileName gibt nichts zurück
 
Zitat:

Zitat von Luckie
Der Klssen name vom Notepad ist wahrscheinlich nicht "Notepad":
Delphi-Quellcode:
hWnd_ := FindWindow('Notepad', nil);

Doch ^^ ... ich hab nachgeguggt! Außerdem würde ansonsten ja die andere Message kommen.
Zitat:

Zitat von Luckie
Desweiteren würde ich den Vorschlag mit GetLastError nicht so einfach abtun, wer weiß, was eventuell noch shcief geht. :roll:

Was verbreche ich denn noch alles? :gruebel: ;)

Kann jemand den code bei sich testen, ob er da funktioniert, bitte!

ciao, Philipp

Luckie 21. Nov 2004 19:33

Re: GetWindowModuleFileName gibt nichts zurück
 
Zitat:

Zitat von c113plpbr
Was verbreche ich denn noch alles? :gruebel: ;)

So lange du nicht GetLastError aufrufst, wirst du es nie erfahren. :roll:


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:00 Uhr.
Seite 1 von 2  1 2      

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