Re: GetWinFileName



On May 6, 1:42 pm, battles <batt...@xxxxxxxxxxxxxx> wrote:
I have a dll that passes the handle of any programs that start on a
computer to my program. I am trying to get the function that I copied
from news below to give me the executable's name upon passing the
handle to it. The function, however, always passes back my own
program's executable name. The handle I pass to the function is not
mine. Can anyone see if I am doing something wrong?

type GetWinFileNameA = function(hWnd : HWND; FileName : PChar;
Length : Integer):Integer;stdcall;

function GetFileNameFromWindow(hWnd : HWND):string;
var
hModule : THandle;
GetWinFileNameAProc : GetWinFileNameA;
Buffer : array[0..255] of Char;
begin
hModule := LoadLibrary('USER32.DLL');
@GetWinFileNameAProc := GetProcAddress(hModule,
'GetWindowModuleFileNameA');
GetWinFileNameAProc(hWnd, Buffer, 255);
Result := Buffer;
end;

Note: I don't know if this would be a problem, but I tried to use
'hModule : HMODULE' but HMODULE is causing an error.

Using outdated code, it should work fine on Win98.
Handles aren't shared between all processes after that.

Search MSDN for PSAPI

---
Geoff
.



Relevant Pages

  • GetWinFileName
    ... I have a dll that passes the handle of any programs that start on a ... hModule: THandle; ... GetWinFileNameAProc: GetWinFileNameA; ... GetWinFileNameAProc(hWnd, Buffer, 255); ...
    (comp.lang.pascal.delphi.misc)
  • Re: GetModuleFileNameEx
    ... HMODULE hModule, ... LPTSTR lpFilename, // buffer that receives the path ... Pointer to the buffer that receives the fully qualified path to the module. ... Specifies the size, in bytes, of the lpFilename buffer. ...
    (microsoft.public.vc.language)