Solved

CListCtrl->GetItem() across processes

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
format the code in java 6 93
java ^ examples 8 65
withoutTen challenge 14 121
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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