6 messages in net.java.dev.jna.usersRe: [jna-users] Fw: GetWindowModuleFi...
FromSent OnAttachments
Dominik JallJul 23, 2008 12:17 pm 
Michael Brewer-DavisJul 23, 2008 1:53 pm 
Michael Brewer-DavisJul 23, 2008 2:16 pm 
Dominik JallJul 23, 2008 4:23 pm 
Michael Brewer-DavisJul 23, 2008 4:50 pm 
Daniel KaufmannJul 26, 2008 1:15 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Fw: GetWindowModuleFileName() callActions...
From:Daniel Kaufmann (dani@gmail.com)
Date:Jul 26, 2008 1:15:00 pm
List:net.java.dev.jna.users

The problem might be due to the OS you are using, according to the link below
module handles are not shared by all processes so you can't use this function: "However, in Windows NT 4.0 and Windows 2000, since module handles are no longer
shared by all processes as they were on Windows 95 and 98, these APIs do not
return information about windows and modules in other processes. To get more information on Windows 2000, use the Process Status Helper set of
APIs (known as PSAPI, see Psapi.h include file), available since Windows NT 4.0.
APIs such as GetModuleFileNameEx and GetModuleBaseName offer equivalent
functionality. "

Assuming you are in Windows 2000 or higher, for getting the module name for a
window use GetWindowThreadProcessId to get the process id, then open the process
(OpenProcess function) with enough access level, and then call
GetModuleFileNameEx (hModule would be NULL).

For identifying the cause of this and other problems you might find useful to
get the error code.Call Native.setPreserveLastError(true) to ensure the error
code is preserved, and then call Native.getLastError() and check whether it is
different than 0 after every call. You might not have permission, the buffer is too small or some other problem
that cause the call to fail and it might not be because you are not calling the
function properly, so it is always advisable to check the last error if the
functions returns an error (for GetModuleBaseName it is probably returning 0 or
-1, it is not clear in the documentation. For GetWindowThreadProcessId it will
return NULL if it fails. (you should check the last error only if the function
fails, otherwise it might have a value different than 0 from a previous error).

Daniel

----- Original Message ----- From: "Michael Brewer-Davis" <mich@tech4learning.com> To: <use@jna.dev.java.net> Sent: Wednesday, July 23, 2008 8:51 PM Subject: Re: [jna-users] Fw: GetWindowModuleFileName() call

I'm not sure of the semantics of the GetWindowModuleFileName() call. Perhaps the handle is owned by Java even though the window is not?

You might look at: http://support.microsoft.com/kb/228469