Solved

External application List to memo

Posted on 2006-11-15
8
891 Views
Last Modified: 2008-01-09
Hi.

How can i pass the content of a list of an external application to my memo ?

This is a part of my code :
...
     cnt:=ListView_GetItemCount(StrToInt(Edit1.Text)); //Handle of the list component (SysListView)
     GetMem(lpBuff, 200);
     for I:=0 to cnt-1 do
     begin
         ListView_GetItemText(Handle, I, 0, lpBuff, 200);
         Memo1.Lines.Add(string(lpBuff));
     end;
     FreeMem(lpBuff);
...

But his doesnt work. It brings weird stuff..

Thanks in advance.
0
Comment
Question by:CodedK
  • 3
  • 3
  • 2
8 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 17946134
is lpBuff of type pchar or pointer? if pointer, make it pchar. can't see anything else wrong.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17946154
Hi Ciuly.

Its Pchar...

One line thats wrong is : >> ListView_GetItemText(Handle, I, 0, lpBuff, 200);

It should be :                 >> ListView_GetItemText(StrToInt(Edit1.Text), I, 0, lpBuff, 200);

But everytime i try to do it the external application crash (I've tried many apps not just one)
0
 
LVL 28

Expert Comment

by:2266180
ID: 17946398
hm.. I did some investigation and it seems that this might be "a process accessing another process memory" issue. I am not exactly sure how to fix this. I was thinking to allocate the memory in adifferent way but can't seem to find a function that would allow me to set a flag so that the memory can be shared across processes. didn't work much with this sort of stuff.
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 200 total points
ID: 17947155

I can provide a solution, but its NT based only due to the call to the API calls used (NT/Win2k/XP/2003). Anyways, you have 2 problems:

1 - Reading / passing memory in another process. (you can't pass memory from your process to another, it just does not work that way.)
2 - A lot of list view handlers don't respond to the ListView_GetItemText, but they ALL respond to ListView_GetItem

So this means allocating memory in the other process, then reading / writing / passing that memory pointer. I have source that simplifies much of this, and can be downloaded from:

http://users.adelphia.net/~rllibby/downloads/processmemory.zip

Include the ProcessMemory unit in your uses clause, then try the following code. The code allocates a block of memory to use as the list view item record, and another to use as the string pointer to pass. Once the remote funtion fills in the list view item, you only have to read the string blocks LocalMemory pointer (which handles the reading from remote to a local storage area).

Let me know if you have problems or questions,
Russell

---
var  pmRemote:      TProcessMemory;
     szString:      String;
     lvItem:        TLVItem;
     handle:        HWND;
     cnt:           Integer;
     i:             Integer;
     idxItem:       Integer;
     idxString:     Integer;
begin

  // Get handle to list view in remote process
  handle:=StrToInt(Edit1.Text);

  // Create handler for remote process
  pmRemote:=TProcessMemory.CreateFromHwnd(handle);
  try
     // Allocate block for the lvItem and the string to read the text from
     idxItem:=pmRemote.Add(SizeOf(TLVItem));
     idxString:=pmRemote.Add(1024);
     // Get list count
     cnt:=ListView_GetItemCount(handle);
     // Walk items
     for i:=0 to cnt-1 do
     begin
        // Clear local item
        FillChar(lvItem, SizeOf(TLVItem), 0);
        // Set params
        lvItem.mask:=LVIF_TEXT;
        lvItem.iItem:=i;
        lvItem.iSubItem:=0;
        lvItem.pszText:=pmRemote[idxString].Memory;
        lvItem.cchTextMax:=1024;
        // Set the remote memory pointer
        pmRemote[idxItem].Write(lvItem, SizeOf(TLVItem));
        // Get the item
        if ListView_GetItem(handle, TLVItem(pmRemote[idxItem].Memory^)) then
        begin
           // Get string from local memory part of handler
           szString:=PChar(pmRemote[idxString].LocalMemory);
           // Read local memory (which handles the transfer)
           Memo1.Lines.Add(szString);
        end;
     end;
  finally
     // Free object
     pmRemote.Free;
  end;

end;
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Author Comment

by:CodedK
ID: 17959151
Thank you Russell, it works.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17960465
Welcome..

You *are* going to close the question? right? <g>

Russell
0
 
LVL 16

Author Comment

by:CodedK
ID: 17960533
I'm sorry ...
I thought i did ...
 
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17960586
lol, no worries...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 79
Delphi Firemonkey Need Sample for Online Shopping Example. 2 120
oracle global variables 4 63
Firemonkey android show image from resource ? 1 33
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now