举个例子, 跨进程的ListView项目读取函数:<br><br>function ListView_GetItemText_Ex(hwndLV: HWND; i, iSubItem: Integer;<br> pszText: PChar; cchTextMax: Integer): Integer;<br>var<br> LVItem: TLVItem;<br> ProcessID, ProcessHD, Temp: DWORD;<br> MemPoint: Pointer;<br>begin<br> GetWindowThreadProcessId(hwndLV, ProcessID);<br><br> ProcessHD := OpenProcess(<br> PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE,<br> FALSE, ProcessID);<br><br> MemPoint := VirtualAllocEx(ProcessHD, nil, SizeOf(TLVItem) + cchTextMax,<br> MEM_COMMIT, PAGE_READWRITE);<br><br> LVItem.iSubItem := iSubItem;<br> LVItem.cchTextMax := cchTextMax;<br> LVItem.pszText := PChar(Integer(MemPoint) + SizeOf(TLVItem));<br><br> WriteProcessMemory(ProcessHD, MemPoint, @LVItem, SizeOf(TLVItem), Temp);<br> Result := SendMessage(hwndLV, LVM_GETITEMTEXT, i, Integer(MemPoint));<br><br> ReadProcessMemory(ProcessHD, Pointer(Integer(MemPoint) + SizeOf(TLVItem)),<br> pszText, cchTextMax, Temp);<br><br> VirtualFreeEx(ProcessHD, MemPoint, SizeOf(TLVItem) + cchTextMax, MEM_DECOMMIT);<br> VirtualFreeEx(ProcessHD, MemPoint, 0, MEM_RELEASE);<br>end;