//Written in C Language
int RListView_GetItemText_Remote(HWND hwndLV,int nItem,int nSubItem,LPSTR szText,int nTextLen)
{
*szText=0;
// If the window under the cursor isn't a ListView, we have nothing to do.
if (hwndLV == NULL)
return 0;
// Open a handle to the remote process's kernel object
DWORD dwProcessId;
GetWindowThreadProcessId(hwndLV, &dwProcessId);
HANDLE hProcess = OpenProcess(
PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
FALSE, dwProcessId);
if (hProcess == NULL) {
// MessageBox(hwnd, __TEXT("Could not communicate with process"),
// g_szAppName, MB_OK | MB_ICONWARNING);
return 0;
}
// Prepare a buffer to hold the ListView's data.
// Note: Hardcoded maximum of 10240 chars for clipboard data.
// Note: Clipboard only accepts data that is in a block allocated with
// GlobalAlloc using the GMEM_MOVEABLE and GMEM_DDESHARE flags.
HGLOBAL hClipData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
sizeof(TCHAR) * 10240);
LPTSTR pClipData = (LPTSTR) GlobalLock(hClipData);
pClipData[0] = 0;
// Allocate memory in the remote process's address space
LV_ITEM* plvi = (LV_ITEM*) VirtualAllocEx(hProcess,
NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
// Get each ListView item's text data
// Initialize a local LV_ITEM structure
LV_ITEM lvi;
lvi.mask = LVIF_TEXT;
lvi.iItem = nItem;
lvi.iSubItem = nSubItem;
// NOTE: The text data immediately follows the LV_ITEM structure
// in the memory block allocated in the remote process.
lvi.pszText = (LPTSTR) (plvi + 1);
lvi.cchTextMax = 100;
// Write the local LV_ITEM structure to the remote memory block
WriteProcessMemory(hProcess, plvi, &lvi, sizeof(lvi), NULL);
// Tell the ListView control to fill the remote LV_ITEM structure
ListView_GetItem(hwndLV, plvi);
// Read the remote text string into the end of our clipboard buffer
ReadProcessMemory(hProcess, plvi + 1,
pClipData, 1024, NULL);
// Free the memory in the remote process's address space
VirtualFreeEx(hProcess, plvi, 0, MEM_RELEASE);
// Cleanup and put our results on the clipboard
CloseHandle(hProcess);
strcpy(szText,pClipData);
return strlen(szText);
}