Solved

CListCtrl->GetItem() across processes

Posted on 1998-12-03
5
892 Views
Last Modified: 2013-11-20
I need to get the text from a multi column listview in an Application I dont have src code for.
I can get a handle to the listview, attach a listctrl and do things like get an itemcount, and call deleteItem.

The problem comes when I try to call GetItem or GetItemText.
I've been told its because passing memory pointers across processes is not straight forward.

Fine, But can it be done. I have src for the program getting the information, not for the program the listctrl is in.

Has any one done this, or seen a solution for it ?

thanks ,

Ian
ianw@microfocus.co.uk
0
Comment
Question by:ianwhite
  • 3
5 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1325711
Using the common controls across processes do not work. In order to retrieve information about a common control across process boundaries, it is necessary to write a DLL that can be injected into the target process space. Usually, writing a system hook will do the job the quickest. Then you need to write a process that communicates with the DLL to get the DLL to do that thing you need, but in the context of the target process. The DLL has to then write the information into a memory map so that another process can access it.

What you're trying to do is not trivial and that is why the solution is that much harder.
0
 

Author Comment

by:ianwhite
ID: 1325712
Ok thanks so far, but I'm still a little confused.
Does that mean I need to enable the process the owns the list box to load the dll, or is it possible to force the dll to become part of that applications process space ?
My problem is I dont have source code for the target App, so is this going to stop me dead ?

Also, is that problem solved by writing a system hook, or was that how you were recomending to read from the listctrl, once the dll was in the process space ?

cheers !
0
 

Author Comment

by:ianwhite
ID: 1325713
Please see my comments, can you provide some more information ?

thanks,
0
 
LVL 1

Accepted Solution

by:
bitq earned 200 total points
ID: 1325714
I think you may do it this way

First i think that thui was right!
You must write a DLL!
And it's very complex!

1.We gonna get the Handle of the window & the List Box:

you can use FindWindow to find the App's window
the parameters of FindWindow you can get from Spy++
or other tools,get the HWND

if the ListBox in a dialog
that's fine.you can get it's ID the only ID
from spy++,then use GetDlgItem() get it.

code:

CWnd *pWnd;
pWnd=CWnd::FindWindow(windowclass,windowname);

//The windowclass & windowname are const strings
//that you get from spy
CListBox *pListBox;
pListBox=pWnd->GetDlgItem(THELISTBOX_ID);
//THELISTBOX_ID is a const number you get from spy
//So you get the CListBox
//but you CAN'T use GetItemText or others NOW!

2.Write a DLL to broken process wall

If you know little about Hook & dll
i sujest you give up.

you can use a globle GETMESSAGE HOOK
and when you want get some data from ListBox
you can send a USER MESSAGE to the listbox;
you hook func check Handle of HOOK callback func
if same as ListBox you want,call GetItemText

!!AND important!Send a WM_COPYDATA message to your main app
the detail of WM_COPYDATA can got from VC helps.

the code:

in your Dll

#pragma data_seg("mydata",SRW)
HWND hListBox=NULL;
BOOL bGetting=FALSE;
HWND hWndToGet;
#pragma data_seg

__declspec(dllexport) void Begin(HWND hWndToWatch)
{
    hListBox=hWndToWatch;
    SetWindowsHookEx(WH_GETMESSAGE,myhookproc,
         hDllMod,//Get at start of dllMain
         GetWindowThreadProcessId(hListBox,NULL)
         );

}

__declspec(dllexport) void Get(DWORD message)
{
    bGetting=TRUE;
    PostMessage(hListBox,message,0,0);
    bGetting=FALSE;
}

LRESULT CALLBACK myhookproc(int code,WPARAM wParam,LPARAM lParam)
{
     if(bGetting)
     {
     MSG *pMsg=(MSG *)lParam;
     switch(pMsg->message)
         {
           .
           .
//         do you work depend on pMsg->message
//you can store the number result such as
//Get GetItemCount in the vars of dll
//but must in share seg
//when you want to send some string or sth
//you must send a WM_COPYDATA message to your
//main app
           .
           .
          }
     }
bGetting=FALSE;
}

3.create message maping on WM_COPYDATA
then
i think it'll work

The code i wrote is simple
I have no much idle
If you don't clear
View MSDN or codeguru etc
And some book's of M$ press

Good Luck!

0
 

Author Comment

by:ianwhite
ID: 1325715
Cheers bitq.

I've not used Hooks before, but have been playing around with a couple of samples from CodeGuru.

I think I'll be able to sort it out from here on in!

thanks again.

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
Error on moodle after upgrade 3 123
mapBully challenge 6 115
unix example issues 18 76
Trying to run powershell  in a batch file. How do I do this? 8 68
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

867 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

17 Experts available now in Live!

Get 1:1 Help Now