Results 1 to 31 of 31

Thread: External listview (nearly a year later still no results)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    External listview (nearly a year later still no results)

    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,


  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    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:
    VB Code:
    1. [COLOR=Blue]Dim[/COLOR] processID [COLOR=Blue]As Long[/COLOR]
    2. [COLOR=Blue]Dim[/COLOR] proc [COLOR=Blue]As Long[/COLOR]
    3.  
    4.     '/// get the processID of the listview ...
    5.     GetWindowThreadProcessId(" handle to Listview here !!! " , processID)
    6.     '/// now you have the processID ...
    7.     proc = OpenProcess(PROCESS_VM_OPERATION [COLOR=Blue]Or[/COLOR] PROCESS_VM_READ [COLOR=Blue]Or[/COLOR]  PROCESS_VM_WRITE [COLOR=Blue]Or[/COLOR] PROCESS_QUERY_INFORMATION , [COLOR=Blue]False[/COLOR], processID)
    8.  
    9. [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]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    Re: External listview (nearly a year later still no results)

    still no joy returns null strings

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    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]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    Re: External listview (nearly a year later still no results)

    Sorry Im in vb6!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    Re: External listview (nearly a year later still no results)

    dynamic_sysop I surpose it would be a bit much to ask for an example in vb?

    Its Yahoo chat room lists that im messing with by the way.

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    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]

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    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.

    Thanks

  9. #9
    New Member
    Join Date
    Mar 2006
    Posts
    3

    Re: External listview (nearly a year later still no results)

    The Scripit offered here did return 0 as Process Id
    VB Code:
    1. Function GetListViewProcId(Ihwnd As Long) As Long
    2.  Dim processID As Long
    3.  Dim proc As Long
    4.  Dim ThreadID As Long
    5.  
    6.     '/// get the processID of the listview ...
    7.     ThreadID = GetWindowThreadProcessId(Ihwnd, processID)
    8.     '/// now you have the processID ...
    9.     proc = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE Or PROCESS_QUERY_INFORMATION, False, processID)
    10.     GetListViewProcId = proc
    11.    
    12. End Function


    This Script give a correct ThreadID to the listview But processID is 0 can any one give a hint plz
    Last edited by Servant; Mar 28th, 2006 at 07:34 PM.

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: External listview (nearly a year later still no results)

    The process ID of the listview should be the same for it's parent window, try getting that process ID.

  11. #11
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    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:
    1. Public Declare Function installHook Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\Debug\getListView.dll" (ByVal hwnd As Integer) As Integer
    2. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.      Dim hTarget As Integer 'the handle to the target ListView control, Im sure you could implement the code to get the handle
    4.      Dim res As Integer = installHook(hTarget)
    5. End Sub

  12. #12
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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

  13. #13
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    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:
    1. Private Declare Function installHook Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\getListView\getListView.dll" (ByVal hwnd As Long) As Long
    2. Private Declare Function removeHook Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\getListView\getListView.dll" () As Long
    3. Private Declare Sub doSelect Lib "C:\Program Files\Microsoft Visual Studio\MyProjects\getListView\getListView\getListView.dll" ()
    4.  
    5.  
    6. Private Sub Command1_Click()
    7. Dim x As Long
    8. Dim targetHwnd as Long   'you need the targets window handle
    9. x = installHook(targetHwnd)
    10.  
    11. End Sub
    12.  
    13. Private Sub Command2_Click()  
    14. Call doSelect   'this lets you select all the items after calling installHook
    15. End Sub
    16.  
    17. Private Sub Command3_Click()
    18. Dim x As Long
    19. x = removeHook()  'removes the hook
    20. End Sub
    Attached Files Attached Files

  14. #14
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Talking 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

  15. #15
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    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.

  16. #16
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: External listview (nearly a year later still no results)

    Quote 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.

  17. #17
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: External listview (nearly a year later still no results)

    Perhaps the path of the dll when you declare the functions is in the wrong path.

    Private Declare Function removeHook Lib "C:\getListView.dll" () As Long <- maybe you might want to make sure about the path.

  18. #18
    New Member
    Join Date
    Mar 2006
    Posts
    3

    Re: External listview (nearly a year later still no results)

    I have now a complete module that Handle the External list view working good and and no crashes. if u are interested plz let me know

  19. #19
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: External listview (nearly a year later still no results)

    Quote Originally Posted by Servant
    I have now a complete module that Handle the External list view working good and and no crashes. if u are interested plz let me know
    Thanks could u upload the complete project that allow me highlight external listview.

  20. #20
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Re: External listview (nearly a year later still no results)

    I could really use that example too. Please someone send it to me.
    [email protected]

  21. #21
    Junior Member
    Join Date
    Aug 2006
    Posts
    16

    Re: External listview (nearly a year later still no results)

    I could really use that example too. Servant, please send it to me.
    [email protected]

    thx in advance.
    Last edited by marco2250; Aug 28th, 2006 at 10:12 AM.

  22. #22
    Junior Member
    Join Date
    Aug 2006
    Posts
    16

    Question 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;
    }
    I've edited getListView.def

    Code:
    LIBRARY getListView
    
    EXPORTS
    	installHook
    	getItemText
    	getItemCount
    	getSubItemText
    DLL compiles with success.

    In my test app (VB.NET):

    Code:
        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.

    I found this code (merged with your code to get subitem text) here:
    http://www.codeproject.com/listctrl/fexportlistview.asp


    Please, help me.

  23. #23
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: External listview (nearly a year later still no results)

    Marco, you may want to check this thread:

    http://www.vbforums.com/showthread.php?t=397764

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    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

  25. #25
    Junior Member
    Join Date
    Aug 2006
    Posts
    16

    Re: External listview (nearly a year later still no results)

    cr250, please, can you send your code to get external listview items??

    I'll search on the net how we can get listview item tooltip.

    thx in advance.

    best regards,
    marco alves

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    Re: External listview (nearly a year later still no results)

    i'll make a post containing it in a minute in new thread
    If you can’t help, dont change the subject with useless questions about the problem

  27. #27
    Junior Member
    Join Date
    Aug 2006
    Posts
    16

    Re: External listview (nearly a year later still no results)

    ok, paste the link here, please (other people will can access it easily in the future). thx a lot!

  28. #28
    New Member
    Join Date
    Aug 2006
    Posts
    3

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    4. 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
    5. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    6. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
    7. 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
    8. Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
    9. 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
    10. 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
    11. 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
    12. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    13. 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
    14.  
    15. Private Const PROCESS_VM_OPERATION = &H8
    16. Private Const PROCESS_VM_READ = &H10
    17. Private Const PROCESS_VM_WRITE = &H20
    18. Private Const MAX_LVMSTRING As Long = 255
    19. Private Const MEM_COMMIT = &H1000
    20. Private Const MEM_DECOMMIT = &H4000
    21. Private Const MEM_RELEASE = &H8000
    22. Private Const PAGE_READWRITE = &H4
    23. Private Const LVIF_TEXT As Long = &H1
    24. Private Const LVM_FIRST = &H1000
    25. Private Const LVM_GETITEMTEXT = LVM_FIRST + 45
    26. Private Const LVM_GETITEMCOUNT = LVM_FIRST + 4
    27.  
    28. Private Type LV_ITEM
    29.    mask         As Long
    30.    iItem        As Long
    31.    iSubItem     As Long
    32.    state        As Long
    33.    stateMask    As Long
    34.    pszText      As Long
    35.    cchTextMax   As Long
    36.    iImage       As Long
    37.    lParam       As Long
    38.    iIndent      As Long
    39. End Type
    40.  
    41. Private Function GetListviewItem(ByVal hWindow As Long, ByVal iItem As Long, ByVal subItem As Long) As String
    42. Dim Result As Long, pHandle As Long, ProcessID As Long, Index As Long
    43. Dim pStrBufferMemory As Long, pMyItemMemory As Long, strLength As Long
    44. Dim strBuffer As String, tmpString As String, LVItem As LV_ITEM
    45.  
    46.     GetWindowThreadProcessId hWindow, ProcessID
    47.  
    48.     pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, ProcessID)
    49.    
    50.     pStrBufferMemory = VirtualAllocEx(pHandle, 0, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE)
    51.  
    52.     LVItem.mask = LVIF_TEXT
    53.     LVItem.iSubItem = subItem
    54.     LVItem.pszText = pStrBufferMemory
    55.     LVItem.cchTextMax = MAX_LVMSTRING
    56.  
    57.     pMyItemMemory = VirtualAllocEx(pHandle, 0, LenB(LVItem), MEM_COMMIT, PAGE_READWRITE)
    58.  
    59.     Result = WriteProcessMemory(pHandle, pMyItemMemory, LVItem, Len(LVItem), 0)
    60.  
    61.     strLength = SendMessage(hWindow, LVM_GETITEMTEXT, iItem, ByVal pMyItemMemory)
    62.     strBuffer = Space(strLength)
    63.     Result = ReadProcessMemoryStr(pHandle, pStrBufferMemory, strBuffer, strLength, 0)
    64.  
    65.     Result = VirtualFreeEx(pHandle, pStrBufferMemory, 0&, MEM_RELEASE)
    66.     Result = VirtualFreeEx(pHandle, pMyItemMemory, 0&, MEM_RELEASE)
    67.     Result = CloseHandle(pHandle)
    68.    
    69.     GetListviewItem = strBuffer
    70.    
    71. End Function
    72.  
    73. Private Function GetHandle(ParentTitle As String, ParentWindow As String, ChildWindow As String) As Long
    74. Dim hWnd1 As Long, hWndEx As Long
    75.  
    76.     hWnd1 = FindWindow(vbNullString, ParentTitle)
    77.     If hWnd1 <> 0 Then
    78.         hWndEx = FindWindowEx(hWnd1, 0&, ParentWindow, vbNullString)
    79.         hWndEx = FindWindowEx(hWndEx, 0&, ChildWindow, vbNullString)
    80.         GetHandle = hWndEx
    81.     Else
    82.         Debug.Print "Could not get handle"
    83.     End If
    84.    
    85. End Function
    86.  
    87. Private Sub Form_Load()
    88. Dim hWnd1 As Long, Count As Integer, i As Integer
    89.    
    90.     hWnd1 = GetHandle("External App Title", "Parent of LV", "SysListView32")
    91.     If hWnd1 <> 0 Then
    92.         Count = SendMessage(hWnd1, LVM_GETITEMCOUNT, 0&, 0&)
    93.         For i = 0 To Count - 1
    94.             Debug.Print GetListviewItem(hWnd1, i, 0)
    95.         Next i
    96.     End If
    97.    
    98. End Sub

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    205

    Re: External listview (nearly a year later still no results)

    yes thats the same one i have
    If you can’t help, dont change the subject with useless questions about the problem

  30. #30
    New Member
    Join Date
    Apr 2007
    Posts
    10

    Re: External listview (nearly a year later still no results)

    Quote 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.

  31. #31
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: External listview (nearly a year later still no results)

    Welcome to the forums.

    Quote 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.

    http://www.vbforums.com/showthread.php?t=458328
    http://www.vbforums.com/showthread.php?t=458438

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width