3 messages in net.java.dev.jna.usersRe: [jna-users] psapi function declar...
FromSent OnAttachments
Pradyumna AcharJul 7, 2007 7:10 am 
Timothy WallJul 7, 2007 9:20 am 
Pradyumna AcharJul 7, 2007 12:24 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] psapi function declarationActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jul 7, 2007 9:20:47 am
List:net.java.dev.jna.users

Look carefully at the header definition. GetModuleBaseName is a macro that expands to either GetModuleBaseNameA/W based on whether you're compiling MBCS or UNICODE.

Take a look at how the example w32 API libraries are set up; you can either do it that way, or change your method name to GetModuleBaseNameA. Note that if you use the UNICODE version (-W), you will need to change the buffer to be of type char[] instead of type byte[].

On Jul 7, 2007, at 10:10 AM, Pradyumna Achar wrote:

Hi,

I've found jna simple and easy to use. Thank you for a great toolkit. While using psapi.dll, I am encountering one small issue.

I have an interface Psapi.java:

public interface Psapi extends StdCallLibrary { Psapi INSTANCE = (Psapi)Native.loadLibrary("C:\\windows\ \system32\\psapi.dll", Psapi.class); int GetModuleBaseName(Pointer hWnd, Pointer hModule, byte[] outBuffer, int bufLength); }

In another class which implements this interface Psapi,

Psapi psapi = Psapi.INSTANCE; ... byte[] modNameBuffer = new byte[2000]; IntByReference pid = new IntByReference(); user32.GetWindowThreadProcessId (hWnd, pid); psapi.GetModuleBaseName(pid.getPointer(), null, modNameBuffer, 1000);

The program runs fine until the call to GetModuleBaseName is encountered, where it throws this exception: java.lang.UnsatisfiedLinkError : Cannot locate function 'GetModuleBaseName' at com.sun.jna.NativeLibrary.getFunctionAddress (NativeLibrary.java:193) at com.sun.jna.Function.<init>(Function.java:108) at com.sun.jna.NativeLibrary.getFunction (NativeLibrary.java:180) at com.sun.jna.Library$Handler.invoke(Library.java:144) at $Proxy2.GetModuleBaseName(Unknown Source) at com.ibm.taskviewer.TaskGetter$1.callback(TaskGetter.java:43) at com.sun.jna.Function.invokeInt(Native Method) at com.sun.jna.Function.invoke(Function.java:327) at com.sun.jna.Library$Handler.invoke(Library.java:148) at $Proxy0.EnumWindows(Unknown Source) at com.ibm.taskviewer.TaskGetter.loadWindowHandleList (TaskGetter.java:96) at com.ibm.taskviewer.TaskGetterTestApp.main (TaskGetterTestApp.java:16) Exception in thread "main"

The signature of GetModuleBaseName is this: DWORD WINAPI GetModuleBaseName( HANDLE hProcess, HMODULE hModule, LPTSTR lpBaseName, DWORD nSize );After getting this exception, I downloaded the jna.jar again (to be sure that I'm not using an older one), but the problem remains. My operating system is Windows XP SP2.

Am I making a mistake in int GetModuleBaseName(Pointer hWnd, Pointer hModule, byte[] outBuffer, int bufLength); ?

Thank you.

Regards, Pradyumna