From what i've read from others, they say you need to do it from within the external app's process memory. So I made this code that did just that. I tried it on Windows Explorer and it gave me the correct text.
i used c++ and vb.net
for the c++ dll:
now for the vb.net code that calls the dll function installHook():Code:#include "stdafx.h" #include "Commctrl.h" #pragma data_seg(".shared") HWND _hTarget = 0; HHOOK hook=0; #pragma data_seg() #pragma comment(linker, "/SECTION:.shared,RWS") LVITEM *lvItem; char lpText[255]; HINSTANCE hInst; bool flag = true;; //send LVM_GETITEMTEXT message from within external app's process int getLVText(HWND hTarget) { lvItem = new LVITEM; lvItem->iSubItem = 0; lvItem->cchTextMax = 255; lvItem->pszText = lpText; int res = SendMessage(hTarget, LVM_GETITEMTEXT, 0, (long)lvItem); if (res != 0) { flag = false; MessageBox(NULL, lvItem->pszText, "", MB_OK); //messagebox shows the listview item string return 1; } return 0; } BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { hInst = (HINSTANCE)hModule; return TRUE; } LRESULT CALLBACK hookproc(int nCode, WPARAM wParam, LPARAM lParam) { if(flag) //I put the flag so it only calls getLVText once { getLVText(_hTarget); } return ::CallNextHookEx(hook, nCode, wParam, lParam); } //these codes injects the dll into external app's process __declspec(dllexport) int _stdcall installHook(HWND hTarget) { _hTarget = hTarget; DWORD tid; tid = ::GetWindowThreadProcessId(hTarget, 0); hook = ::SetWindowsHookEx(WH_GETMESSAGE, hookproc, hInst, tid); if (hook != NULL) return 1; return 0; }
VB Code:
Public Declare Function installHook Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\Debug\getListView.dll" (ByVal hwnd As Integer) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim hTarget As Integer 'the handle to the target ListView control, Im sure you could implement the code to get the handle Dim res As Integer = installHook(hTarget) End Sub
I hope getting the text of the listview items is what you wanted because it took me a while to do this. This is probably not the exact code you'll be using in your program, but it should give you an idea of how to get the text of the listview item.




Reply With Quote