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:
Public Const PROCESS_QUERY_INFORMATION = 1024
Public Const PROCESS_VM_OPERATION = &H8
Public Const PROCESS_VM_READ = &H10
Public Const PROCESS_VM_WRITE = &H20
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const MAX_LVMSTRING As Long = 255
Public Const MEM_COMMIT = &H1000
Public Const PAGE_READWRITE = &H4
Public Const LVIF_TEXT As Long = &H1
Public Type LV_ITEMA
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As Long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
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
Public Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
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
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
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
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Function GetListviewItem(ByVal hWindow As Long, ByVal ProcessID As Long, ByVal pColumn As Long, ByVal pRow As Long) As String
result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
result = CloseHandle(pHandle)
If Len(tmpString) > 0 Then GetListviewItem = tmpString
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?
Re: External listview (nearly a year later still no results)
are you using VB6 by the look of those calls?
if so...
you need to be calling GetWindowThreadProcessId first on the listview's handle. *** note , if you are using VB.NET, you need to be specifying IntPtr's instead of the Long's ***
eg:
[COLOR=Green]'/// then continue with your[/COLOR] [B][COLOR=DarkOrange]VirtualAllocEx[/COLOR][/B]
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
Re: External listview (nearly a year later still no results)
you didn't confirm if it's vb6 you are using.
you will need to convert the pointer to a string when using readmemory whatever you are using.
if you know C# / VB.NET @ all , here's a link to an example in C# ( also an MFC example ) , which i have tested in C# and it works.
i joined an msn groups chatroom and added the FindWindow / FindWindowEx api's to the linked example, found the Handle for the listview in the msn chatroom & retrieved the names in the listview.
the link to the example is ... Crossing the process boundry with .NET
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
Re: External listview (nearly a year later still no results)
i don't have vb6 loaded on my pc, i only run vs2003 & vs2005.
what benefits will you gain from tapping in to the nick list on yahoo?
i'm of the understanding that their chat servers are tight run with little scope for sending any additional commands.
i used to run msn chatrooms & made numerous irc bots for msn chat, took me a while to tap in to the msn listview in those days too
but i ended up being one of only 2 people that had managed it
if i ever get chance, with havin 5 kids @ home i can knock an example up in vb.net, but that's as close as i can get with it these days.
so you would have to deal with the pointers to string in the vb6 way ( maybe copymemory to a byte array, then using StrConv will guide you )
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
Re: External listview (nearly a year later still no results)
Thanks for all your efforts, I'm new to C++ so maybe source files would help me out, I seen the c++ code but don't know enough about c++ to compile it, etc.
Re: External listview (nearly a year later still no results)
To select all item in listview, try this:
i used c++ and vb.net
for the c++ dll:
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->mask = LVIF_STATE;
lvItem->stateMask = LVIS_SELECTED;
lvItem->state = 15;
int res = SendMessage(hTarget, LVM_SETITEMSTATE, -1, (long)lvItem);
if (res != 0)
{
flag = false;
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;
}
now for the vb.net code that calls the dll function installHook():
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
Re: External listview (nearly a year later still no results)
Thank for sharing this code benmartin101 . Could u tell me how use your code in visual studio 6 . I want to be able to external list view items from with in m vb6 application so i be happy if u explain to me how i can compile and run it.Thanks
Re: External listview (nearly a year later still no results)
Well, the c++ code can't really be done in vb6 because to inject code, it has to be in a win32 dll. You need to create the dll. I include the c++ project so you can compile it yourself.
For the vb6 code:
VB Code:
Private Declare Function installHook Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\getListView\getListView.dll" (ByVal hwnd As Long) As Long
Private Declare Function removeHook Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\getListView\getListView.dll" () As Long
Private Declare Sub doSelect Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\getListView\getListView.dll" ()
Private Sub Command1_Click()
Dim x As Long
Dim targetHwnd as Long 'you need the targets window handle
x = installHook(targetHwnd)
End Sub
Private Sub Command2_Click()
Call doSelect 'this lets you select all the items after calling installHook
Re: External listview (nearly a year later still no results)
Thank u for u reply. I created a project and placed 3 buttons in the form and when i click on them i get the following errors:
code :
Code:
Private Declare Function installHook Lib "C:\getListView.dll" (ByVal hwnd As Long) As Long
Private Declare Function removeHook Lib "C:\getListView.dll" () As Long
Private Declare Sub doSelect Lib "C:\getListView.dll" ()
Private Sub Command1_Click()
Dim x As Long
Dim targetHwnd As Long 'you need the targets window handle
x = installHook(targetHwnd)
End Sub
Private Sub Command2_Click()
Call doSelect 'this lets you select all the items after calling installHook
End Sub
Private Sub Command3_Click()
Dim x As Long
x = removeHook() 'removes the hook
End Sub
Furthermore, how should i display the items that i got from external app to my form if it rurns ?Thanks
Re: External listview (nearly a year later still no results)
I'm not sure what exactly you want it to do, but the program just selects all the items; basically highlights them as if you clicked on the file/folder.
Now for the error, are you using the dll that was in the zip file? If so, that may not be current, you might want to run the project and compile the dll yourself.
Re: External listview (nearly a year later still no results)
Originally Posted by benmartin101
I'm not sure what exactly you want it to do, but the program just selects all the items; basically highlights them as if you clicked on the file/folder.
Now for the error, are you using the dll that was in the zip file? If so, that may not be current, you might want to run the project and compile the dll yourself.
thank u for u reply. well i have an external listview open and tried it with new compiled dll from your above zip file but still i get those errors. Do i need any perticule components or module or my the above code is wrong ?Thanks
Last edited by tony007; Apr 14th, 2006 at 11:59 PM.
Re: External listview (nearly a year later still no results)
benmartin101,
I've got your code and it works fine for me. thx a lot.
Now, I'm trying to get listview subitem text.
So, I've edited your code and ad a new function, getSubItemText:
PS: I don't know C++.
Code:
__declspec(dllexport) LPCSTR _stdcall getSubItemText(HWND lvwHwnd, int item, int index)
{
// LVITEM struct (see MSDN for content) :
LVITEM lvi;
// 5000 MAX LENGTH
// String buffer for pszText member of LVITEM struct :
unsigned char LVtext[5000];
memset(&lvi, 0, sizeof(lvi)); // Clean up before action
// Fill in the members of the LVITEM struct :
lvi.mask = LVIF_TEXT;
// Minimum here to take care of the pszText member
// - see other LVIF_xxx constants in MSDN
lvi.state = 0;
lvi.stateMask = 0;
// lvi.iSubItem : not here, see 'j' loop below
lvi.cchTextMax = 5000 - 1;
// Length of string to be copied into pszText member
lvi.pszText = (LPSTR)LVtext;
// String buffer for pszText member
// Important member of LVITEM struct you
// need to fill in (j=0 : item; j>0 : subitem) :
lvi.iSubItem = index;
// Retrieve the text in an item or a subitem of line 'i' :
SendMessage(lvwHwnd, LVM_GETITEMTEXT, (WPARAM) item, (LPARAM) &lvi);
return (LPCSTR)LVtext;
}
Public Declare Function getSubItemText Lib "C:\getListView\Debug\getListView.dll" (ByVal hwnd As Integer, ByVal item As Integer, ByVal index As Integer) As IntPtr
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strPtr As IntPtr = getSubItemText(1447178, 0, 1) '0 based
Dim str As String = Marshal.PtrToStringAnsi(strPtr)
MsgBox(str)
End Sub
So, i click button 1 (hooked!), click button2 (show me the right item text! ), and click button 3 and got a lot of special characters, i.e., not the subitem text.
Re: External listview (nearly a year later still no results)
Any of you guys no about getting the tooltip text of a listview item? I have some code from a guy here to get the listview items (external program) but no idea bout getting the tooltip text
If you can’t help, dont change the subject with useless questions about the problem
Re: External listview (nearly a year later still no results)
I didn't try the code Cr250 posted but here is similar looking code that works for me. Unfortunately it does not seem to be releasing the allocated memory when I use it.
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private 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
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemoryStr Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const PROCESS_VM_OPERATION = &H8
Private Const PROCESS_VM_READ = &H10
Private Const PROCESS_VM_WRITE = &H20
Private Const MAX_LVMSTRING As Long = 255
Private Const MEM_COMMIT = &H1000
Private Const MEM_DECOMMIT = &H4000
Private Const MEM_RELEASE = &H8000
Private Const PAGE_READWRITE = &H4
Private Const LVIF_TEXT As Long = &H1
Private Const LVM_FIRST = &H1000
Private Const LVM_GETITEMTEXT = LVM_FIRST + 45
Private Const LVM_GETITEMCOUNT = LVM_FIRST + 4
Private Type LV_ITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As Long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Function GetListviewItem(ByVal hWindow As Long, ByVal iItem As Long, ByVal subItem As Long) As String
Dim Result As Long, pHandle As Long, ProcessID As Long, Index As Long
Dim pStrBufferMemory As Long, pMyItemMemory As Long, strLength As Long
Dim strBuffer As String, tmpString As String, LVItem As LV_ITEM
GetWindowThreadProcessId hWindow, ProcessID
pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, ProcessID)
Re: External listview (nearly a year later still no results)
Originally Posted by Cr250
yes thats the same one i have
trying to copy code to try it but can't find out how to copy it. If I just highlight code in box and copy it, all the linefeeds are missing. How do I copy code with all the linefeeds intact. Also did you ever get this working.
Thanks.
Re: External listview (nearly a year later still no results)
Welcome to the forums.
Originally Posted by ed08724
trying to copy code to try it but can't find out how to copy it. If I just highlight code in box and copy it, all the linefeeds are missing. How do I copy code with all the linefeeds intact.
This is a know issue with the code highlight feature. See these two threads by Martin Liss that address this.