Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 545081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:43:25+00:00 2026-05-13T10:43:25+00:00

I have an application with a ListView (‘SysListView32’) control, from which I would like

  • 0

I have an application with a ListView (‘SysListView32’) control, from which I would like to extract data. The control has 4 columns, only textual data.

I have been playing around the following lines (found online somewhere):

VALUE_LENGTH = 256
bufferlength_int=struct.pack('i', VALUE_LENGTH)
count = win32gui.SendMessage(TargetHwnd, commctrl.LVM_GETITEMCOUNT, 0, 0)
for ItemIndex in range(count):
    valuebuffer = array.array('c',bufferlength_int + " " * (VALUE_LENGTH - len(bufferlength_int)))
    ListItems = win32gui.SendMessage(TargetHwnd, commctrl.LVM_GETITEMTEXT, ItemIndex, valuebuffer)

[The above code may not be entirely executable, as I stripped it from irrelevant stuff. but the gist is certainly here.]

This seems to run ok but I must be doing something wrong – I get all sorts of mostly-zeroed data buffers in return, and none of the actual text contents I was looking for.

Any suggestions?

Thanks,
Yonatan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:43:26+00:00Added an answer on May 13, 2026 at 10:43 am

    Well, it turns out I was wrong on several points there. However it is possible to do by allocating memory inside the target process, constructing the required struct (LVITEM) there, sending the message and reading back the result from the buffer allocated in said process.

    For the sake of completeness, I attach a code example for reading SysListView32 items from a foreign process, given a window handle of the control.

    from win32con import PAGE_READWRITE, MEM_COMMIT, MEM_RESERVE, MEM_RELEASE,\
        PROCESS_ALL_ACCESS
    from commctrl import LVM_GETITEMTEXT, LVM_GETITEMCOUNT
    
    import struct
    import ctypes
    import win32api
    import win32gui
    
    GetWindowThreadProcessId = ctypes.windll.user32.GetWindowThreadProcessId
    VirtualAllocEx = ctypes.windll.kernel32.VirtualAllocEx
    VirtualFreeEx = ctypes.windll.kernel32.VirtualFreeEx
    OpenProcess = ctypes.windll.kernel32.OpenProcess
    WriteProcessMemory = ctypes.windll.kernel32.WriteProcessMemory
    ReadProcessMemory = ctypes.windll.kernel32.ReadProcessMemory
    memcpy = ctypes.cdll.msvcrt.memcpy
    
    
    def readListViewItems(hwnd, column_index=0):
    
        # Allocate virtual memory inside target process
        pid = ctypes.create_string_buffer(4)
        p_pid = ctypes.addressof(pid)
        GetWindowThreadProcessId(hwnd, p_pid) # process owning the given hwnd
        hProcHnd = OpenProcess(PROCESS_ALL_ACCESS, False, struct.unpack("i",pid)[0])
        pLVI = VirtualAllocEx(hProcHnd, 0, 4096, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE)
        pBuffer = VirtualAllocEx(hProcHnd, 0, 4096, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE)
    
        # Prepare an LVITEM record and write it to target process memory
        lvitem_str = struct.pack('iiiiiiiii', *[0,0,column_index,0,0,pBuffer,4096,0,0])
        lvitem_buffer = ctypes.create_string_buffer(lvitem_str)
        copied = ctypes.create_string_buffer(4)
        p_copied = ctypes.addressof(copied)
        WriteProcessMemory(hProcHnd, pLVI, ctypes.addressof(lvitem_buffer), ctypes.sizeof(lvitem_buffer), p_copied)
    
        # iterate items in the SysListView32 control
        num_items = win32gui.SendMessage(hwnd, LVM_GETITEMCOUNT)
        item_texts = []
        for item_index in range(num_items):
            win32gui.SendMessage(hwnd, LVM_GETITEMTEXT, item_index, pLVI)
            target_buff = ctypes.create_string_buffer(4096)
            ReadProcessMemory(hProcHnd, pBuffer, ctypes.addressof(target_buff), 4096, p_copied)
            item_texts.append(target_buff.value)
    
        VirtualFreeEx(hProcHnd, pBuffer, 0, MEM_RELEASE)
        VirtualFreeEx(hProcHnd, pLVI, 0, MEM_RELEASE)
        win32api.CloseHandle(hProcHnd)
        return item_texts
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.