Hello,
below is my working C# code for getting item text from syslistview32 control of another application.
IntPtr SysListView32 = Value[1];
int count = SendMessage(SysListView32, LVM_GETITEMCOUNT,0,"0");
LVITEM lvi = new LVITEM();
lvi.mask = LVIF_TEXT;
lvi.cchTextMax = 512;
lvi.iItem = 1;
lvi.iSubItem = 0;
lvi.pszText = Marshal.AllocHGlobal(512);
IntPtr ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(lvi));
Marshal.StructureToPtr(lvi, ptrLvi, false);
SendMessage(SysListView32, LVM_GETITEM, IntPtr.Zero, ptrLvi);
string itemText = Marshal.PtrToStringAuto(lvi.pszText);
[StructLayoutAttribute(LayoutKind.Sequential)]
private struct LVITEM {
public uint mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public IntPtr lParam;
}
I have correct handle for SysListview32 control cause I am getting correct items count as "4" & Target SysListView32 application is shown as below
http://www.freeimagehosting.net/t/f07ab.jpg
But target aplication having this syslistview32 control always hanged when I tried to sendmessage for getting item with
lvi.iItem = 1;
lvi.iSubItem = 0;
SendMessage(SysListView32, LVM_GETITEM, IntPtr.Zero, ptrLvi);
I think it has to with something memmory allocation problem.
can anybody please tell me where did I make mistake in above code?
Note : Both visual studio & Target SysteListView32 control application running as administrator in my Win 7 pc.