Click to See Complete Forum and Search --> : Uniquely select and double click an item in the List View


scody
November 14th, 2007, 11:05 PM
Hi,

I am new to Windows programming.

I am trying to uniquely select and double click an item in the list view (SysListView32) in third party software. This task is somewhat similar to MyProgram trying to double click an item in a ControlPanel-like list view.

To accomplish this I am sending a LVM_FINDITEM message to get the item index of the item to be double clicked.

LVFINDINFO lvfi;
ZeroMemory(&lvfi, sizeof(LVFINDINFO));
lvfi.flags = LVFI_STRING;
lvfi.psz = (LPCTSTR)"Item Name";

int itemIndex = ::SendMessage( HWnd, LVM_FINDITEM, (WPARAM)(int)(iStart), (LPARAM)(const LVFINDINFO *)(&lvfi));

This send message is causing a runtime error. After going through some forums and message boards I found that this is due to one of the message parameter which is a pointer to a structure, as you cannot pass a pointer-to-memory to another process.

Now I would like to know how to custom marshal this message to the other process?

OR

Any alternative solution to uniquely select and double click an item in the list view.

Any idea or solution to this problem is greatly appreciated. Thanks in advance.

VladimirF
November 16th, 2007, 01:44 PM
This is a pretty advanced topic. You can easily crash that other app (as you've already noticed).
Common solution is to inject your code into that process, and then communicate between that injected module and your app.
But in your relatively simple case you could simply use the same message you are using, the only difference is – pass a pointer to the host’s memory, not yours.
You’d need to use OpenProcess() to get access to the host, VirtualAllocEx() to allocate some memory for your structure, fill that memory by WriteProcessMemory(), SendMessage(), ReadProcessMemory() to get your data and finally VirtualFreeEx() and CloseHandle() to clean things up.