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:Michael Brewer-Davis (mich@tech4learning.com)
Date:Jul 23, 2008 1:53:04 pm
List:net.java.dev.jna.users

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

Dominik Jall wrote:

Hi guys,

I am trying to get a list of all windows and print out all the corresponding module names for them using this code:

User32 user32 = User32.INSTANCE; Kernel32 kernel32 = Kernel32.INSTANCE;

user32.EnumWindows(new User32.WNDENUMPROC() { int count; public boolean callback(HWND hWnd, Pointer userData) { System.out.println("Found window " + hWnd + ", total " + ++count);

User32 user32 = User32.INSTANCE; byte text[] = new byte[1024];

user32.GetWindowModuleFileName(hWnd, text, 1024);

String test = Native.toString(text);

System.out.println(test);

return true; } }, null);

But apparently. only the first character (i.e. "C:\Program Files\myexe.exe" --> "C") ist printed out. What am I doing wrong?

Greetings, dom