// Approach 1: Use EM_GETSELTEXT (works for rich edit controls) wchar_t buffer[8192] = {0}; int textLength = SendMessageW(focusedControl, EM_GETSELTEXT, 0, (LPARAM)buffer);
You must first invoke OpenProcess to open the target process, then call VirtualAllocEx to allocate memory, followed by SendMessage(hwnd, EM_GETSELTEXT, 0, (LPARAM)pRemoteBuf); because the edit box window belongs to another process.