GetWinFileName



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.
.



Relevant Pages

  • Re: GetWinFileName
    ... from news below to give me the executable's name upon passing the ... 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)
  • Re: DllMain vs. DllMain
    ... Lots of Win32 code assumes HMODULE is a pointer to ... the beginning of DLL in memory. ... Lots of Win32 code (including VC CRT) ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Pfad einer Dll
    ... Da kam der Explorer zurück. ... >> Über die Funktion GetModuleFileName versuche ich zur Zeit den Pfad der ... >> Dll rauszulesen. ... > HMODULE hModule, ...
    (microsoft.public.de.vc)
  • RE: Regular DLL How To register
    ... You cannot register a non COM dll(which doesn't export DllRegisterServer func) ... FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName); ... > I have created Regular dll statically linked with mfc (no automation ... > client EXE will load that dll from that path.? ...
    (microsoft.public.vc.mfc)