Ok, I got the sample Buzzer.java to work, so I know my environment is set up right.
Now my first real test is to run the callback function EnumWindows and the function GetWindowText for each returned window handle.
Here is my code:
package test;
import com.jniwrapper.Parameter;
import com.jniwrapper.Function;
import com.jniwrapper.Int32;
import java.util.List;
public class Test
{
public static void main(String[] args)
{
Parameter retVal = null;
EnumWindowsProc enumWindowsProc = new EnumWindowsProc();
Function.call("user32.dll", "EnumWindows", retVal, enumWindowsProc, new Int32(1234));
List list = enumWindowsProc.getHwndList();
for (int i = 0; i < list.size(); i++)
{
System.out.println("hwnd = " + list.get(i));
}
}
}
package test;
import com.jniwrapper.Callback;
import com.jniwrapper.Pointer;
import com.jniwrapper.UInt32;
import com.jniwrapper.Parameter;
import java.util.List;
import java.util.ArrayList;
public class EnumWindowsProc extends Callback
{
private Pointer.Void _hwnd = new Pointer.Void();
private UInt32 _lParam = new UInt32();
private List hwndList = new ArrayList();
public EnumWindowsProc()
{
init(new Parameter[] { _hwnd, _lParam }, null);
}
public List getHwndList()
{
return hwndList;
}
public void callback()
{
//System.out.println("window found : " + _hwnd + ", " + _lParam);
hwndList.add(_hwnd);
//Parameter retVal = null;
//Str _lpstr = null;
//Function.call("user32.dll","GetWindowText",retVal,new Parameter[]{ _hwnd, _lpstr, new Int(100)});
//System.out.println("retVal = " + retVal);
}
}
When i run it, I get this error:
Exception c0000005, at 00000000
Access violation: attempting to read memory at address 00000000
Native function stack data: 3112720,0,20007,6d0063,31101b0,31101b0,74746553,73676e69
Exception in thread "main" com.jniwrapper.FunctionExecutionException: c0000005
at com.jniwrapper.Function.invokeCFunc(Native Method)
at com.jniwrapper.FunctionCall.a(SourceFile:126)
at com.jniwrapper.FunctionCall.call(SourceFile:34)
at com.jniwrapper.Function.invoke(SourceFile:164)
at com.jniwrapper.Function.call(SourceFile:257)
at com.jniwrapper.Function.call(SourceFile:302)
at test.Test.main(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Can anybody help me?
Regards,
Bill