0

I would like to inspect the contents of a multi-column list view that is part of another application. I would like to get its rows with columns being separately accessible. I have the HWND of the control. The listview in question is the one that commctl32.dll provides. So far I've been looking at this article but I'm a bit confused about it, and this looks like the more "arcane" parts of the WinAPI. Any help would be appreciated.

Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
  • Use automation to do this. The control lives in another process and so the code you link to is no use. You can only make that work with ReadProcessMemory/WriteProcessMemory hacking. No fun, and of course automation is designed to solve the problem in a clean way. Start with UIAutomation. – David Heffernan Jun 12 '14 at 09:29
  • @DavidHeffernan Are you sure? The WinAPI seems to be not very restrictive about returning stuff from another process. For example, GetWindowText works regardless of whose handle is being used. – Tamás Szelei Jun 12 '14 at 09:55
  • Yes I am sure. Win32 won't marshal the text for list view messages. There are about a gazillion hits on this is you search the web. Why of why are you rejecting automation? You even tagged the question automation. – David Heffernan Jun 12 '14 at 09:57
  • @DavidHeffernan I'm not rejecting automation... – Tamás Szelei Jun 12 '14 at 09:59
  • Oh good. That's the answer then. – David Heffernan Jun 12 '14 at 10:00

1 Answers1

0

The article that you link to covers list view handling when the control is in your process. Things are complicated for a list view in a different process. In that scenario the messages you need involves pointers to structs, for instance pointers to LVITEM structs. The system won't marshal these pointers across the process boundary. So in order to make this work you need to allocate memory in the virtual address space of the other process. That involves calls to OpenProcess, VirtualAllocEx, WriteProcessMemory and ReadProcessMemory. Not much fun. There are many examples of this process available on the web, and I don't want to add another one here.

However, this is the wrong way to tackle the problem. You should use one of the automation interfaces to automate this other application. Start by looking at UI Automation.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Can you expand a bit on a possible UIAutomation based solution? I can obtain an AutomationElement, but can't find an example on how to read the list elements from it. – Tamás Szelei Jun 12 '14 at 12:14
  • http://stackoverflow.com/questions/10799757/read-cell-items-from-data-grid-in-syslistview32-of-another-application-using-c-s – David Heffernan Jun 13 '14 at 19:04