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 2:16:58 pm
List:net.java.dev.jna.users

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.

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.