LVM_GETITEM Problem HELP!

  • Thread starter Thread starter Mark Everett
  • Start date Start date
M

Mark Everett

Hi all,

I can't work out why this doesn't work - any ideas?
const int BUFFER_SIZE = 512;
LV_ITEM lvi = new LV_ITEM();
lvi.mask = LVIF_TEXT;
lvi.cchTextMax = BUFFER_SIZE;
lvi.iItem = i;
lvi.iSubItem = 1;
lvi.pszText = Marshal.AllocHGlobal(BUFFER_SIZE);
SendMessage(window.Window, LVM_GETITEM, 0, ref lvi);
string text = Marshal.PtrToStringAuto(lvi.pszText);

I have tried everything I can think of and text ends up containing
gibberish! The window handle it grabs from is correct - and
LVM_GETITEMCOUNT is fine. My definitions are such:

const int LVM_FIRST = 0x1000;
const int LVM_GETITEMCOUNT = LVM_FIRST + 4;
const int LVM_GETITEM = LVM_FIRST + 5;
const int LVIF_TEXT = 0x0001;

[DllImport("user32.dll")]
static extern int SendMessage(IntPtr window, int message, int wparam,
ref LV_ITEM lparam);

[StructLayoutAttribute(LayoutKind.Sequential)]
struct LV_ITEM
{
public UInt32 mask;
public Int32 iItem;
public Int32 iSubItem;
public UInt32 state;
public UInt32 stateMask;
public IntPtr pszText;
public Int32 cchTextMax;
public Int32 iImage;
public IntPtr lParam;
}

Any ideas would be greatly appreciated!
Many Thanks
Mark Everett
 
Back
Top