Hi all, I posted this thread nearly a year ago:

http://www.vbforums.com/showthread.p...ernal+listview


Still waiting on a reply, maybe one day.


Well anyway that old thread doesnt matter now. im about crazy, after reading endless threads on what i need and want but never actually any working example.. always a if or but or something.


I need to get the items of a listview in an external program, after over a year of looking for this on and off this is the closest (i think?) bit of code that can do it: (By someone called hax0r i think..)


VB Code:
  1. Public Const PROCESS_QUERY_INFORMATION = 1024
  2. Public Const PROCESS_VM_OPERATION = &H8
  3. Public Const PROCESS_VM_READ = &H10
  4. Public Const PROCESS_VM_WRITE = &H20
  5. Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
  6. Public Const MAX_LVMSTRING As Long = 255
  7. Public Const MEM_COMMIT = &H1000
  8. Public Const PAGE_READWRITE = &H4
  9. Public Const LVIF_TEXT As Long = &H1
  10.  
  11. Public Type LV_ITEMA
  12.    mask         As Long
  13.    iItem        As Long
  14.    iSubItem     As Long
  15.    state        As Long
  16.    stateMask    As Long
  17.    pszText      As Long
  18.    cchTextMax   As Long
  19.    iImage       As Long
  20.    lParam       As Long
  21.    iIndent      As Long
  22. End Type
  23.  
  24. Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
  25. Public Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
  26. Public Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
  27. Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  28. Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
  29.  
  30. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
  31.  
  32. Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  33.  
  34. Public Function GetListviewItem(ByVal hWindow As Long, ByVal ProcessID As Long, ByVal pColumn As Long, ByVal pRow As Long) As String
  35.     Dim result              As Long
  36.     Dim myItem              As LV_ITEMA
  37.     Dim pHandle             As Long
  38.     Dim pStrBufferMemory    As Long
  39.     Dim pMyItemMemory       As Long
  40.     Dim strBuffer()         As Byte
  41.     Dim index               As Long
  42.     Dim tmpString           As String
  43.     Dim strLength           As Long
  44.    
  45.     '**********************
  46.     'init the string buffer
  47.     '**********************
  48.     ReDim strBuffer(MAX_LVMSTRING)
  49.    
  50.     '***********************************************************
  51.     'open a handle to the process and allocate the string buffer
  52.     '***********************************************************
  53.     pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, ProcessID)
  54.     pStrBufferMemory = VirtualAllocEx(pHandle, 0, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE)
  55.        
  56.     '************************************************************************************
  57.     'initialize the local LV_ITEM structure
  58.     'The myItem.iSubItem member is set to the index of the column that is being retrieved
  59.     '************************************************************************************
  60.     myItem.mask = LVIF_TEXT
  61.     myItem.iSubItem = pColumn
  62.     myItem.pszText = pStrBufferMemory
  63.     myItem.cchTextMax = MAX_LVMSTRING
  64.    
  65.     '**********************************************************
  66.     'write the structure into the remote process's memory space
  67.     '**********************************************************
  68.     pMyItemMemory = VirtualAllocEx(pHandle, 0, Len(myItem), MEM_COMMIT, PAGE_READWRITE)
  69.     result = WriteProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
  70.    
  71.     '*************************************************************
  72.     'send the get the item message and write back the memory space
  73.     '*************************************************************
  74.     result = SendMessage(hWindow, LVM_GETITEMTEXT, pRow, ByVal pMyItemMemory)
  75.     result = ReadProcessMemory(pHandle, pStrBufferMemory, strBuffer(0), MAX_LVMSTRING, 0)
  76.     result = ReadProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
  77.      
  78.     '**************************************************
  79.     'turn the byte array into a string and send it back
  80.     '**************************************************
  81.     For index = LBound(strBuffer) To UBound(strBuffer)
  82.         If Chr(strBuffer(index)) = vbNullChar Then Exit For
  83.         tmpString = tmpString & Chr(strBuffer(index))
  84.     Next index
  85.    
  86.     tmpString = Trim(tmpString)
  87.    
  88.     '**************************************************
  89.     'deallocate the memory and close the process handle
  90.     '**************************************************
  91.     result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
  92.     result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
  93.    
  94.     result = CloseHandle(pHandle)
  95.    
  96.     If Len(tmpString) > 0 Then GetListviewItem = tmpString
  97.  
  98. End Function


Sadly he didnt mention how to call it or anything about processid but i searched on "processid" and couldnt find much as im not even sure what im looking for.

So maybe just an example/ more detail on this function would be great..

Im pretty sure the listview i want to get at isnt user drawn, i logged its "listview" messages and didnt see any wm_user msgs... when i logged another listview i seen lots of wm_users, if im only seeing listview messages does this means its not user drawn?


Please help
Regards,