views:

158

answers:

1

Hello. I've been trying to select an item on an external listview but it seems to only work with listviews that accept multiple selected items:

HANDLE process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, 0xC30); 

LVITEM lvi;

LVITEM* _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); 

 lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
 lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
 lvi.mask = LVIF_STATE;

 WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); 
 int abc = ::SendMessage((HWND)0x00080D6A, LVM_SETITEMSTATE, (WPARAM)0, (LPARAM)_lvi); 
 VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
+1  A: 

Hey Jorge.

Your code looks valid, and should work, I've tested it internally within my own GUI application itself, so perhaps the issue is in your attempt to access from outside of the actual process. I notice that you have hard coded the HWND for the ListView. Also I would be careful with the fact that you immediately release the virtual memory after sending the message. Remember that the sent message is going to be posted (assuming the HWND is correct) to the ListView message pump. It may not be taken care of immediately and by the time it is, there is a decent chance you've already released the memory of the LVITEM. Try it internally within the GUI, make sure you have that working, then I would suggest going back to this approach and setting appropriate debug points (within the GUI, if this is someone else's, make your own simple dialog with a listView) to make sure that the message is being received appropriately, and that the memory is valid.

DeusAduro