var ListView : hWnd;
TmpPC : PChar;
PListItem : ^LV_ITEM;
ListItem : LV_ITEM;
CurrentPos,
ItemCount : Integer;
pid : dword;
// process ID
ph : dword;
// process handle
c1 : dword;
// dummy variable
arrCh :
array [0..255]
of char;
begin
listbox1.Clear;
ListView:=Self.windowHandle;
// ask the process ID of the other process
GetWindowThreadProcessID(ListView, @pid);
logInfo('
pid',pid);
// open the other process
ph := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
// allocate memory in the other process
TmpPC := VirtualAllocEx(ph,
nil, 255, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
PListItem := VirtualAllocEx(ph,
nil, sizeOf(LV_ITEM), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
ItemCount:=ListView_GetItemCount(ListView);
logInfo('
ItemCount',ItemCount);
for CurrentPos:=0
to ItemCount-1
do begin
ListItem.mask:=LVIF_TEXT;
ListItem.iItem:=CurrentPos;
ListItem.iSubItem:=0;
ListItem.pszText:=TmpPC;
ListItem.cchTextMax:=255;
// write the prepared item to the other process
WriteProcessMemory(ph, PListItem, @ListItem, sizeOf(ListItem), c1);
// ask the item content
if ListView_GetItem(ListView, PListItem^)
then begin
// read the item string back from the other process and show it
ReadProcessMemory(ph, TmpPC, @arrCh, 255, c1);
listBox1.Items.Add(arrCh);
end;
end;
// free the memory of the other process
VirtualFreeEx(ph, TmpPC, 0, MEM_RELEASE);
VirtualFreeEx(ph, PListItem, 0, MEM_RELEASE);
// close handle
CloseHandle(ph);