

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
6 messages in net.java.dev.jna.usersRe: [jna-users] Fw: GetWindowModuleFi...| From | Sent On | Attachments |
|---|---|---|
| Dominik Jall | Jul 23, 2008 12:17 pm | |
| Michael Brewer-Davis | Jul 23, 2008 1:53 pm | |
| Michael Brewer-Davis | Jul 23, 2008 2:16 pm | |
| Dominik Jall | Jul 23, 2008 4:23 pm | |
| Michael Brewer-Davis | Jul 23, 2008 4:50 pm | |
| Daniel Kaufmann | Jul 26, 2008 1:15 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Fw: GetWindowModuleFileName() call | Actions... |
|---|---|---|
| From: | Dominik Jall (DJA...@de.ibm.com) | |
| Date: | Jul 23, 2008 4:23:36 pm | |
| List: | net.java.dev.jna.users | |
Mike,
thanks for your help. I am one step further, I can now decode the byte array as unicode using this code:
System.setProperty("jna.encoding", "UTF-16LE"); User32 user32 = User32.INSTANCE;
final HWND[] handles = new HWND[500];
user32.EnumWindows(new User32.WNDENUMPROC() { int count; public boolean callback(HWND hWnd, Pointer userData) { System.out.println("Found window " + hWnd + ", total " + ++count); handles[count] = hWnd; return true; } }, null);
for( HWND i : handles) { byte text[] = new byte[1024]; user32.GetWindowModuleFileName(i, text, 1024); String test = Native.toString(text); System.out.println(test); }
But there must be something wrong, because I get like 400 Window handles (which might be ok in Windows), but everytime I get a valid String in my "text" variable, it is the same String:
Here is the first output (window handles):
(...) Found window com.sun.jna.examples.win32.W32API$HWND@10414, total 116 Found window com.sun.jna.examples.win32.W32API$HWND@1040e, total 117 Found window com.sun.jna.examples.win32.W32API$HWND@10412, total 118 Found window com.sun.jna.examples.win32.W32API$HWND@202f2, total 119 Found window com.sun.jna.examples.win32.W32API$HWND@30328, total 120 (...)
Here is the second output (filenames):
(...) C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe C:\Documents and Settings\Administrator\My Documents\IBM Java 50 JDK\bin\javaw.exe (...)
What could that be?
From: Michael Brewer-Davis <mich...@tech4learning.com> To: use...@jna.dev.java.net Date: 23.07.2008 23:24 Subject: Re: [jna-users] Fw: GetWindowModuleFileName() call
Didn't check the JNA example code before responding--the basic idea's still the same, but if you want to use the default example code without adding a char[] variant function, you can:
1) interpret the byte[] as a UTF16 string (be sure your buffer has length 2 * cchFileNameMax) 2) ask JNA to default to ASCII (set "w32.ascii" system property) 3) create an ASCII instance of the User32 library User32 asciiInstance = (User32) Native.loadLibrary("user32", User32.class, ASCII_OPTIONS);
There may be better options someone else can mention.
Michael Brewer-Davis wrote:
Dom,
GetWindowModuleFileName() is one of the many Windows calls that can operate as an ASCII or Unicode function. Your code is defaulting to the
Unicode version:
UINT GetWindowModuleFileNameW(HWND hwnd, LPWSTR pszFileName, UINT cchFileNameMax);
Use a Java char[] buffer instead of a Java byte[] buffer (corresponding to using LPWSTR/wchar_t* instead of LPSTR/char*).
Everything else will be the same--Native.toString(char[]) turns the char[] buffer into a String.
michael







