Cannot use LVM_GETITEMTEXT without crashing target application in C ++

I am trying to grab data from the SysListView32 class (according to Spy ++) from another application. Sending a LVM_GETITEMCOUNT message to this descriptor always returns the correct number of elements. There is a child window, which is SysHeader32, which supposedly contains the header headers.

When I try to send the LVM_GETITEMTEXT message to the target application, it will work. The corresponding code for this post is below:

LPTSTR lpText; LVITEM* lvItem; lvItem = new LVITEM; lvItem->iSubItem = 0; lvItem->cchTextMax = 255; lvItem->pszText = lpText; //SysListViewHandle is the HWND to the SysListView32 'content' window SendMessage(SysListViewHandle, LVM_GETITEMTEXT, 1, (long)lvItem); 

Each cell in the list contains text no more than 50 characters, so the maximum text size must be accurate.

The list structure in which I want to get the data contains 16 columns and a variable number of entries, more than 5, so wParam should be fine. Styles used in this list, - WS_CHILDWINDOW, WS_VISIBLE, WS_TABSTOP, WS_HSCROLL, LVS_REPORT with advanced styles WS_EX_LEFT, WS_EX_LTRREADING, WS_EX_RIGHTSCROLLBAR, WS_EX_NOPARENTNOTIFY, WS_EX_CLIENTEDGE, LVS_GRIDLINES and LVS_FULLROWSELECT.

UISpy can examine this list and find the actual data inside, so I assumed that it would be a walk in the park to use the messages, but this turned out to be wrong: any help would be greatly appreciated.

EDIT: it is worth mentioning the error log on failure: Unhandled exception at 0x77582b87 in applicationname.exe: 0xC0000005: location of access violation record 0x01bc48b0. Call stack location comctl32.dll Dismantling: 77582B87 mov dword ptr [esi], 1

+4
source share
1 answer

Your problem is that since the list view exists in another process, the allocated memory is not valid in this other process. I refer to an article in the Code project that offers a solution.

What else, you do not seem to have allocated any memory for lpText so that it does not work in your own process.

+3
source

Source: https://habr.com/ru/post/1334513/


All Articles