From: Steve on
There is an API called GetModuleFileNameEx which can retrieve a filename
from a process ID which can in turn be retrieved from a HWND.
GetModuleFileNameEx is for NT based machines, so for Windows 95/98/Me, I
need to use GetModuleFileName. But this version requires a module handle
, and it seems to get a module handle using GetModuleHandle which
requires a filename (!?). So, how do I retrieve a filename from a HWND
in Windows 98?
From: Olof Lagerkvist on
Steve wrote:

> There is an API called GetModuleFileNameEx which can retrieve a filename
> from a process ID which can in turn be retrieved from a HWND.
> GetModuleFileNameEx is for NT based machines, so for Windows 95/98/Me, I
> need to use GetModuleFileName. But this version requires a module handle
> , and it seems to get a module handle using GetModuleHandle which
> requires a filename (!?). So, how do I retrieve a filename from a HWND
> in Windows 98?

You can take a look at the Toolhelp32 API. It is available in Win 95,
98, ME, 2000, XP and later, but not in NT 4.0 or erlier.

http://msdn.microsoft.com/library/en-us/perfmon/base/tool_help_functions.asp

--
Olof Lagerkvist
ICQ: 724451
Web: http://here.is/olof

From: Alf P. Steinbach on
* Steve:
> There is an API called GetModuleFileNameEx which can retrieve a filename
> from a process ID which can in turn be retrieved from a HWND.

No, GetModuleFileNameEx requires a process handle + a module handle (the
latter can be retrieved from a HWND). A process ID is not a process handle.


> GetModuleFileNameEx is for NT based machines, so for Windows 95/98/Me, I
> need to use GetModuleFileName. But this version requires a module handle

No, the difference is that GetModuleFileName doesn't take a process
handle argument. So you can't specify the process.


> , and it seems to get a module handle using GetModuleHandle which
> requires a filename (!?).

No, GetModuleFileName doesn't call GetModuleHandle.

And no, GetModuleHandle doesn't require a filename: just pass 0 to
GetModuleHandle to get a module handle for the file used to create the
current (calling) process.


> So, how do I retrieve a filename from a HWND in Windows 98?

Depends which file name you want.

Since most of the information you've given is incorrect, there's no way
to know what your current NT-specific code does: the only thing that's
for sure is that it doesn't do what you've implicitly described.

Which filename do you want?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Steve on
Alf P. Steinbach wrote:
> * Steve:
>> There is an API called GetModuleFileNameEx which can retrieve a
>> filename from a process ID which can in turn be retrieved from a HWND.
>
> No, GetModuleFileNameEx requires a process handle + a module handle (the
> latter can be retrieved from a HWND). A process ID is not a process
> handle.
>
No. GetModuleFileNameEx does not need a module handle. And you retrieve
the process handle from the HWND and not the module handle.
>
>> GetModuleFileNameEx is for NT based machines, so for Windows 95/98/Me,
>> I need to use GetModuleFileName. But this version requires a module
>> handle
>
> No, the difference is that GetModuleFileName doesn't take a process
> handle argument. So you can't specify the process.
>
GetModuleFileNameEx is only available in NT based machines. Therefor,
for NON NT based machines I need to use GetModuleFileName.
>
>> , and it seems to get a module handle using GetModuleHandle which
>> requires a filename (!?).
>
> No, GetModuleFileName doesn't call GetModuleHandle.

I didn't say it did.
>
> And no, GetModuleHandle doesn't require a filename: just pass 0 to
> GetModuleHandle to get a module handle for the file used to create the
> current (calling) process.
>
So what about other processes?
>
>> So, how do I retrieve a filename from a HWND in Windows 98?
>
> Depends which file name you want.
>
> Since most of the information you've given is incorrect, there's no way
> to know what your current NT-specific code does: the only thing that's
> for sure is that it doesn't do what you've implicitly described.
>
> Which filename do you want?
>
Have a look at the subject again: Filename from HWND

I want to retrieve a filename for a given HWND (regardless of what
process the HWND is attached to). I know how to do this using
GetModuleFileNameEx but this cannot be used under Windows 95,98,Me.

So, is there a way that works under all versions of Windows?
From: Alf P. Steinbach on
* Steve:
> Alf P. Steinbach wrote:
>> * Steve:
>>> There is an API called GetModuleFileNameEx which can retrieve a
>>> filename from a process ID which can in turn be retrieved from a HWND.
>>
>> No, GetModuleFileNameEx requires a process handle + a module handle
>> (the latter can be retrieved from a HWND). A process ID is not a
>> process handle.
>>
> No. GetModuleFileNameEx does not need a module handle.

That doesn't make sense to me.

DWORD GetModuleFileNameEx(
HANDLE hProcess,
HMODULE hModule,
LPTSTR lpFilename,
DWORD nSize
);

"hModule [in] Handle to the module."


> And you retrieve
> the process handle from the HWND and not the module handle.

That doesn't make sense to me.

Perhaps you mean that /you/ are retrieving the process handle and not
the module handle?

To retrieve the module handle from a HWND w, call GetWindowLongPtr( w,
GWLP_HINSTANCE ).

To retrieve a process id from a HWND w, call GetWindowThreadProcessId(
w, &processId ).

I don't know how to directly retrieve a process handle from a HWND w.
If you know a simple way, as it seems you indicate, please describe it.


>>> GetModuleFileNameEx is for NT based machines, so for Windows
>>> 95/98/Me, I need to use GetModuleFileName. But this version requires
>>> a module handle
>>
>> No, the difference is that GetModuleFileName doesn't take a process
>> handle argument. So you can't specify the process.
>>
> GetModuleFileNameEx is only available in NT based machines. Therefor,
> for NON NT based machines I need to use GetModuleFileName.
>>
>>> , and it seems to get a module handle using GetModuleHandle which
>>> requires a filename (!?).
>>
>> No, GetModuleFileName doesn't call GetModuleHandle.
>
> I didn't say it did.

That doesn't make sense to me.

Quoted above, you wrote "it seems to get a module handle using
GetModuleHandle".


>> And no, GetModuleHandle doesn't require a filename: just pass 0 to
>> GetModuleHandle to get a module handle for the file used to create the
>> current (calling) process.
>>
> So what about other processes?
>>
>>> So, how do I retrieve a filename from a HWND in Windows 98?
>>
>> Depends which file name you want.
>>
>> Since most of the information you've given is incorrect, there's no
>> way to know what your current NT-specific code does: the only thing
>> that's for sure is that it doesn't do what you've implicitly described.
>>
>> Which filename do you want?
>>
> Have a look at the subject again: Filename from HWND
>
> I want to retrieve a filename for a given HWND (regardless of what
> process the HWND is attached to). I know how to do this using
> GetModuleFileNameEx but this cannot be used under Windows 95,98,Me.
>
> So, is there a way that works under all versions of Windows?

Possibly, but /which/ filename is it you want?

Is it a filename for the executable for the window's process?

Then I suggest follow Olof Lagerkvist's advice in this thread, namely
using the ToolHelp API. One way could be (1) GetWindowThreadProcessId,
(2) CreateToolhelp32Snapshot, (3) Module32First. And if that sometimes
happens to find a module other than the original executable, also
retrieve the module handle in step 1, using GetWindowLongPtr, and use a
loop checking for that module handle in step 3.

There may be some easier and/or more efficient way, I don't know.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 |  Next  |  Last
Pages: 1 2 3 4
Prev: Get Firefox URL?
Next: FindFirstUrlCacheEntry (WinInet)