by vmars » Wed Feb 23, 2005 8:37 pm
The code below runs, but ReadProcessMemory always returns #0(s) in RetBuffer.
LB_GETTEXTLEN always returns 4 in y , so i plugged 'len' with 260 to match RemoteBuff.
I believe LB_GETTEXTLEN must run in remote process; hWnd is OwnerDrawn ListBox,
which is why i have been leaning toward converting your 'RemoteCmdLine.dpr'.
Function LB_GetAllItems(hWnd: THandle; sl: TStrings): string;
var
RetBuffer: string;
i, x, y : Integer; len : dword;
RemoteBuff : pointer; pid, processHandle: dword;
begin
x := SendMessage(hWnd, LB_GETCOUNT, 0, 0);
If x > 0 Then
Begin
GetWindowThreadProcessID(hWnd, @pid);
// hWnd is OwnerDrawn ListBox
processHandle := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
RemoteBuff := AllocMemEx(MAX_PATH, processHandle);
for i := 0 to x - 1 do
begin
len := 260;
y := SendMessage(hWnd, LB_GETTEXTLEN, i, 0);
SetLength(RetBuffer, 260);
SendMessage(hWnd, LB_GETTEXT, i, lParam(PChar(RemoteBuff)));
ReadProcessMemory(processHandle, RemoteBuff, pointer(RetBuffer), len, len);
// ShowMessage('RetBuffer = ' + RetBuffer);
sl.Add(RetBuffer);
end; // for i := 0 to x - 1 do
FreeMemEx(RemoteBuff, processHandle);
CloseHandle(processHandle);
end; // If x > 0 Then
end;
procedure TForm1.GetAllItemsClick(Sender: TObject);
var
sl: TStringList;
ListBox_Handle: THandle;
begin
ListBox_Handle := hWnd; // listbox handle global
sl := TStringList.Create;
try
LB_GetAllItems(ListBox_Handle, sl);
finally
ListBox1.Lines.Text := sl.Text;
sl.Free;
end;
end;