Get ListView item text from another process in VB.NET
I've done it in vb6, but I'm new to vb.net, and don't know how to convert it to .net, can anyone help me?
------- code for getting current selection of another process's listview
Public Function GetLVSelectedIndex(ByVal hlistview As Long) As Long
'returns selected index provided the listview's handle
Dim iCur As Long
Dim count As Integer
count = SendMessage(hlistview, LVM_GETITEMCOUNT, 0, 0)
If count = 0 Then Exit Function
Dim iSel As Long
Dim lvi As LVITEM
Dim plvi As Long
Dim pid As Long
Call GetWindowThreadProcessId(hlistview, pid)
Dim hProcess As Long
Dim dwSize As Long, lWritten As Long
dwSize = Len(lvi)
Dim i As Long
Dim theOS As New OS
If theOS.IsWindowsNT Then
hProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE Or PROCESS_QUERY_INFORMATION, False, pid)
plvi = VirtualAllocEx(hProcess, ByVal 0&, Len(lvi), MEM_COMMIT, PAGE_READWRITE)
For i = 0 To count - 1
'Initialize a local LV_ITEM structure
lvi.mask = LVIF_STATE 'try to get item state
lvi.iItem = i 'index
lvi.iSubItem = 0
lvi.stateMask = LVIS_SELECTED
'Write the local LV_ITEM structure to the remote memory block
WriteProcessMemory hProcess, plvi, ByVal lvi, dwSize, lWritten
'Tell the ListView control to fill the remote LV_ITEM structure
Call SendMessage(hlistview, LVM_GETITEM, 0, plvi)
lWritten = 0
ReadProcessMemory hProcess, plvi, ByVal lvi, dwSize, lWritten
If lvi.state = LVIS_SELECTED Then iCur = i + 1: Exit For
Next i
Call VirtualFreeEx(hProcess, plvi, 0, MEM_RELEASE)
CloseHandle hProcess
Else
iCur = SendMessage(hlistview, LVM_GETNEXTITEM, -1, LVNI_SELECTED)
End If
Set theOS = Nothing
GetLVSelectedIndex = iCur
End Function