private string GetLvItemText(int item)
        {
            const int LVM_GETITEM = 0x1005;
            const int LVIF_TEXT = 0x0001;

            // set address to remote buffer immediately following the lvItem
            var nRemoteBufferPtr = _lpRemoteBuffer.ToInt64() + Marshal.SizeOf(typeof(Interop.TVITEM));

            var lvItem = new Interop.LVITEM
            {
                mask = LVIF_TEXT,
                iItem = item,
                iSubItem = 0,
                pszText = (IntPtr)nRemoteBufferPtr,
                cchTextMax = 50
            };

            // copy local lvItem to remote buffer
            var success = Interop.WriteProcessMemory(_hProcess, _lpRemoteBuffer, ref lvItem,
                Marshal.SizeOf(typeof(Interop.LVITEM)), IntPtr.Zero);
            if (!success)
                ShowErrorMessage(new SystemException("Failed to write to process memory"));

            // Send the message to the remote window with the address of the remote buffer
            if (Interop.SendMessage(_wndListView, LVM_GETITEM, IntPtr.Zero, _lpRemoteBuffer) == IntPtr.Zero)
                return null;

            // copy lvItem back into local buffer (copy whole buffer because we don't yet know how big the string is)
            success = Interop.ReadProcessMemory(_hProcess, _lpRemoteBuffer, _lpLocalBuffer, BufferSize, IntPtr.Zero);
            if (!success)
                ShowErrorMessage(new SystemException("Failed to read from process memory"));

            var localBufferPtr = _lpLocalBuffer.ToInt64() + Marshal.SizeOf(typeof(Interop.TVITEM));
            return Marshal.PtrToStringAnsi((IntPtr)localBufferPtr);
        }
        private void SetLVItemState(int item)
        {
            const int LVM_FIRST        = 0x1000;
            const int LVM_SETITEMSTATE = (LVM_FIRST + 43);
            const int LVIF_STATE       = 0x0008;

            const int LVIS_FOCUSED  = 0x0001;
            const int LVIS_SELECTED = 0x0002;

            Interop.LVITEM lvItem = new Interop.LVITEM();
            lvItem.mask     = LVIF_STATE;
            lvItem.iItem    = item;
            lvItem.iSubItem = 0;

            lvItem.state     = LVIS_FOCUSED | LVIS_SELECTED;
            lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;

            // copy local lvItem to remote buffer
            bool bSuccess = Interop.WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem, Marshal.SizeOf(typeof(Interop.LVITEM)), IntPtr.Zero);

            if (!bSuccess)
            {
                ShowErrorMessage(new SystemException("Failed to write to process memory"));
            }

            // Send the message to the remote window with the address of the remote buffer
            if (Interop.SendMessage(wndListView, LVM_SETITEMSTATE, (IntPtr)item, lpRemoteBuffer) == IntPtr.Zero)
            {
                ShowErrorMessage(new SystemException("LVM_GETITEM Failed "));
            }
        }
        private void SetLVItemState(int item)
        {
            const int LVM_FIRST = 0x1000;
            const int LVM_SETITEMSTATE = LVM_FIRST + 43;
            const int LVIF_STATE = 0x0008;

            const int LVIS_FOCUSED = 0x0001;
            const int LVIS_SELECTED = 0x0002;

            var lvItem = new Interop.LVITEM
            {
                mask = LVIF_STATE,
                iItem = item,
                iSubItem = 0,
                state = LVIS_FOCUSED | LVIS_SELECTED,
                stateMask = LVIS_FOCUSED | LVIS_SELECTED
            };

            // copy local lvItem to remote buffer
            var success = Interop.WriteProcessMemory(_hProcess, _lpRemoteBuffer, ref lvItem,
                Marshal.SizeOf(typeof(Interop.LVITEM)), IntPtr.Zero);
            if (!success)
                ShowErrorMessage(new SystemException("Failed to write to process memory"));

            // Send the message to the remote window with the address of the remote buffer
            if (Interop.SendMessage(_wndListView, LVM_SETITEMSTATE, (IntPtr)item, _lpRemoteBuffer) == IntPtr.Zero)
                ShowErrorMessage(new SystemException("LVM_GETITEM Failed "));
        }
        private string GetLVItemText(int item)
        {
            const int LVM_GETITEM = 0x1005;
            const int LVIF_TEXT   = 0x0001;

            Interop.LVITEM lvItem = new Interop.LVITEM();
            lvItem.mask     = LVIF_TEXT;
            lvItem.iItem    = item;
            lvItem.iSubItem = 0;
            // set address to remote buffer immediately following the lvItem
            lvItem.pszText    = (IntPtr)(lpRemoteBuffer.ToInt32() + Marshal.SizeOf(typeof(Interop.LVITEM)));
            lvItem.cchTextMax = 50;

            // copy local lvItem to remote buffer
            bool bSuccess = Interop.WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem, Marshal.SizeOf(typeof(Interop.LVITEM)), IntPtr.Zero);

            if (!bSuccess)
            {
                ShowErrorMessage(new SystemException("Failed to write to process memory"));
            }

            // Send the message to the remote window with the address of the remote buffer
            if (Interop.SendMessage(wndListView, LVM_GETITEM, IntPtr.Zero, lpRemoteBuffer) == IntPtr.Zero)
            {
                return(null);
            }

            // copy lvItem back into local buffer (copy whole buffer because we don't yet know how big the string is)
            bSuccess = Interop.ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, dwBufferSize, IntPtr.Zero);
            if (!bSuccess)
            {
                ShowErrorMessage(new SystemException("Failed to read from process memory"));
            }

            return(Marshal.PtrToStringAnsi((IntPtr)(lpLocalBuffer.ToInt32() + Marshal.SizeOf(typeof(Interop.LVITEM)))));
        }