LPTSTR (pszText) is a pointer, not a character array. You can use
String or WString depending on whether you are calling the ascii or
unicode version of the function.
I think you're also missing a pointer field after cColumns.
On Feb 27, 2008, at 7:01 AM, Lei Ding wrote:
Hello all!
I am a new user of JNA. What I am trying to do is accessing a 3rd
party program's user interface through Win32 API. More specifically,
read the items of a SysListView32 control in the program(which I
don't have access to it's source code). Here's my Java code:
Comctl32.LVITEM item = new Comctl32.LVITEM();
item.iSubItem = 0;
user32.SendMessage(l_orderList, Comctl32.LVM_GETITEMTEXT, 0,new
byte[256]).intValue();
Yet everytime I run my java program, I got a "The instruction at ...
referenced memory at ... could not be written" error from the native
application(which I am trying to access) and then the native app
crashs.
Note: I've no problem with access to this program's other contents,
such as GetWindowText to all of it's Edit controls.
I thought there were problems with my method signature, so tried
many different kinds but all no luck:
public LRESULT SendMessage(HWND hwnd, int msg, WPARAM wparam,
LVITEM str);
Here's my definition of LVITEM. Thanks a lot!!
public static class LVITEM extends Structure {
public int mask;
public int iItem;
public int iSubItem;
public int state;
public int stateMask;
public byte[] pszText;
public int cchTextMax;
public int iImage;
public Pointer lParam;
public int iIndent;
public int iGroupId;
public int cColumns; // tile view columns
public Pointer piColFmt;
public int iGroup;
/**
*
*/
public LVITEM() {
this.iSubItem = 0;
cchTextMax = 200;
pszText = new byte[200];
pszText[pszText.length -1] = '\0';
allocateMemory();
}
}