Solved

CListCtrl->GetItem() across processes

Posted on 1998-12-03
5
883 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

8 Experts available now in Live!

Get 1:1 Help Now