AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi GetWindowModuleFileName gibt nichts zurück
Thema durchsuchen
Ansicht
Themen-Optionen

GetWindowModuleFileName gibt nichts zurück

Ein Thema von c113plpbr · begonnen am 21. Nov 2004 · letzter Beitrag vom 22. Nov 2004
Antwort Antwort
Seite 2 von 2     12   
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#11

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 19:54
GetModuleFilename funktioniert glaub ich nur wenn das handle zu deiner anwendung gehört, also du zum beispiel eine dll eingebunden hast. Wenn du an den dateinamen der Anwendung willst zu dem das Handle gehört musst du das anders machen.

[Edit]Hab grad mal die Suche bemüht und einen Beitrag gefunden den ich mal gepostet hab der genau das macht was du willst
Hier der Link: http://www.delphipraxis.net/internal...=146809#146809
[/Edit]
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
Benutzerbild von c113plpbr
c113plpbr

Registriert seit: 18. Nov 2003
Ort: localhost
674 Beiträge
 
Delphi 2005 Professional
 
#12

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 20:05
Also, ich hab nun mal GetLastError zu meinen Überwachten "ausdrücken" hinzugefügt (funktionsaufrufe sind gestattet), und bin schritt für schritt durchgegangen, und GetLastError war *immer* 0
Da ist kein "fehler" da ... oder?

@SirThornberry: Sollte dann da nicht zumindest ein Hinweis in der PSDK dazu stehen? Ich hab keinen gesehen ...
Philipp
There is never enough time to do all the nothing you want.
*HABENWILL*
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#13

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 20:08
Guck dir mal den ersten Parameter an:
Zitat:
hModule
[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
Das ist nicht das Fensterhandle, sondern das Dateihandle.

Du müsstest also MSDN-Library durchsuchenGetModuleFileNameEx benutzen. Und dort findest du sogar noch ein Beispiel:
Enumerating All Modules For a Process
To determine which processes have loaded a particular DLL, you must enumerate the modules for each process. The following sample code uses the MSDN-Library durchsuchenEnumProcessModules function to enumerate the modules of current processes in the system.
Code:
#include <windows.h>
#include <stdio.h>
#include "psapi.h"

void PrintModules( DWORD processID )
{
    HMODULE hMods[1024];
    HANDLE hProcess;
    DWORD cbNeeded;
    unsigned int i;

    // Print the process identifier.

    printf( "\nProcess ID: %u\n", processID );

    // Get a list of all the modules in this process.

    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
                                    PROCESS_VM_READ,
                                    FALSE, processID );
    if (NULL == hProcess)
        return;

    if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
    {
        for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
        {
            char szModName[MAX_PATH];

            // Get the full path to the module's file.

            if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
                                      sizeof(szModName)))
            {
                // Print the module name and handle value.

                printf("\t%s (0x%08X)\n", szModName, hMods[i] );
            }
        }
    }

    CloseHandle( hProcess );
}

void main( )
{
    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
        return;

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the name of the modules for each process.

    for ( i = 0; i < cProcesses; i++ )
        PrintModules( aProcesses[i] );
}
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#14

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 20:08
wenn du mal anstelle des notepadhandles das handle der eigenen Anwendung nimmst wirst du sehen das dein Beispiel funktioniert. Daraus hab ich das einfach mal vermutet das es daran liegt das es kein Handle ist das zur eigenen Anwendung gehört. Wenn du eine DLL in dein programm einbindest und in der dll dein source mit dem handle der hostanwendung ausführst sollte das auch funktionieren... naja, wie schon geschrieben hab ich den link zu funktionierendem source schon gepostet.
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
w3seek
(Gast)

n/a Beiträge
 
#15

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 20:12
Zitat von Luckie:
Guck dir mal den ersten Parameter an:
Zitat:
hModule
[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
Das ist nicht das Fensterhandle, sondern das Dateihandle.
Wenn ich dich korrigieren darf, das ist die base adress des modules (also im Grunde ein simpler pointer), kein handle
  Mit Zitat antworten Zitat
Benutzerbild von c113plpbr
c113plpbr

Registriert seit: 18. Nov 2003
Ort: localhost
674 Beiträge
 
Delphi 2005 Professional
 
#16

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 20:13
Zitat von SirThornberry:
[Edit]Hab grad mal die Suche bemüht und einen Beitrag gefunden den ich mal gepostet hab der genau das macht was du willst
Hier der Link: http://www.delphipraxis.net/internal...=146809#146809
[/Edit]
Jup, danke, ich kenne diese Methode, nur frag ich mich trotzdem, warum der obige befehl einfach so ohne Hinweis seinen Dienst verweigert ... (außerdem gefallen mir einzeilige befehle besser, als ganze proceduren ... )

ok, da wohl niemand ne idee hat woran das liegen könnte ... muss ich wohl doch wieder zur längeren Methode greifen ... ... trotzdem danke für eure Ratschläge, Tipps & Bemühungen!

ciao, Philipp

[edit]man seid ihr schnell ... ich wollte es schon aufgeben (hab die letzen posts nimmer gesehen) ... ^^ ... ok, danke[/edit]
Philipp
There is never enough time to do all the nothing you want.
*HABENWILL*
  Mit Zitat antworten Zitat
Benutzerbild von Motzi
Motzi

Registriert seit: 6. Aug 2002
Ort: Wien
598 Beiträge
 
Delphi XE2 Professional
 
#17

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 20:24
Hab mal schnell den Code rausgesucht den ich in meinem X-Spy verwend und bissi angepasst...

Delphi-Quellcode:
function GetWindowModule(Window: HWND): String;
var
  dwProcessID : DWord;
  Process : hProcess;
  Module : hModule;
  Path : array [0..MAX_PATH] of Char;
begin
  GetWindowThreadProcessID(Window, @dwProcessID);
  Module := GetClassLong(Window, GCL_HMODULE);
  if (Module = 0) and (GetLastError <> 0) then
    Result := '(Unavailable)';
  else
  begin
    Process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,
      dwProcessID);
    if Process <> 0 then
    begin
      if GetModuleFileNameEx(Process, Module, Path, MAX_PATH) > 0 then
      begin
        GetLongPathName(Path, Path, MAX_PATH);
        Result := String(Path)
      end
      else
        Result := '(Unavailable)';
      CloseHandle(Process);
    end
    else
      Result := '(Unavailable)';
  end;
end;
@w3seek: jain.. es ist ein Module-Handle.. das PSDK sagt dazu:
Zitat von PSDK:
HMODULE: Handle to a module. The value is the base address of the module.
Manuel Pöter
  Mit Zitat antworten Zitat
w3seek
(Gast)

n/a Beiträge
 
#18

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 21. Nov 2004, 23:21
es ist definitv kein handle weder ein user/gdi object, noch ein kernel handle. es ist einfach ein pointer zur base adresse des moduls. nichts mehr und nichts weniger
  Mit Zitat antworten Zitat
perle

Registriert seit: 8. Apr 2004
183 Beiträge
 
Delphi 7 Enterprise
 
#19

Re: GetWindowModuleFileName gibt nichts zurück

  Alt 22. Nov 2004, 14:27
bei mir geht das so:

Code:
var
 lProcessID: dWord;
 lHandle: THandle;
begin
 GetWindowThreadProcessId(WindowHandle, @lProcessID);
 SetLength(Buffer, MAX_PATH);
 lHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, True, lProcessID);
 if GetModuleFileNameEx(lHandle, 0, PChar(Buffer), MAX_PATH) > 0 then
   SetLength(Buffer, StrLen(PChar(Buffer)));
end;
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


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 09:50 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