Retrieving the contents of a list in someone else's process is a difficult task. Since the list view is in another process , and in the LVM_GETITEM message, LVM_GETITEM need to send an LVITEM structure LVITEM , which should be allocated in a heap of remote process memory .
Here is the code:
Implementation
Appendix: Minimum Windows API Declarations
static class WinAPI { public enum ListViewMessages { LVM_GETITEMTEXT = 0x104B } public enum ListViewItemFilters : uint { LVIF_TEXT = 0x0001, } public const uint MAX_LVMSTRING = 255; [StructLayoutAttribute(LayoutKind.Sequential)] public 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; } [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam); [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId); [Flags] public enum ProcessAccessFlags : uint { VirtualMemoryOperation = 0x0008, VirtualMemoryRead = 0x0010, VirtualMemoryWrite = 0x0020, } [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect); [Flags] public enum AllocationType { Commit = 0x1000, Release = 0x8000, } [Flags] public enum MemoryProtection { ReadWrite = 0x0004, } [DllImport("kernel32.dll")] public static extern IntPtr OpenProcess(ProcessAccessFlags processAccess, bool bInheritHandle, uint processId); [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr hHandle); [DllImport("kernel32.dll")] public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, uint nSize, out int lpNumberOfBytesWritten); [DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] buffer, int dwSize, out IntPtr lpNumberOfBytesRead); [DllImport("kernel32.dll")] public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, AllocationType dwFreeType); }
hillin
source share