Solved

Send message to the external application control

Posted on 2000-03-16
9
503 Views
Last Modified: 2013-12-03
I have tried to send message to the TreeView control to the some external application control. It works fine for messages like TVM_GETNEXTITEM, TVM_SELECTITEM, but it failed for TVM_GETITEM call! The difference is, as I can see it, the TVM_GETITEM need to fill some structure which address I pass as LPARAM SendMessage() call. I get the FALSE as SendMessage(hTV, TVM_GETITEM, 0, &TVItem). Any suggesions? Thanks.
0
Comment
Question by:abondar
  • 4
  • 3
  • 2
9 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
ID: 2625799
The problem is that treeview is in the different address space.

3 ways possible:

1)If another application is written by you, send WM_COPYDATA message with the item text from that app to your first application where you need the item text.

2)Install the windows hook (SetWindowHookEx, for example WH_GETMESSAGE) on the treeview thread (use GetWindowThreadProcessId). You must get an item text inside the hook proc (which resides in a hook dll). It  works because the hook procedure is in the address space of another process.

3) No documented way for 95/98.
For NT/2000:
Alloc memory in the another process's address space using pMem=VirtualAllocEx. Place TVITEM inside pMem using WriteProcessMemory.
Then call SendMessage(hTV,TVM_GETITEM,hTv, pMem). Then use ReadProcessMemory to get result.

Choose the way and ask about details.



0
 
LVL 20

Expert Comment

by:Madshi
ID: 2626905
Good answer, Nick...  :-)

abondar, if you choose (3), then you might be interested in the following (undocumented) functions which allocate memory in another process under all win9x systems (well, the functions in reality allocate memory in shared memory, but that doesn't matter):

function SharedMem9x_Alloc   (              size: cardinal) : pointer;  stdcall; external 'comCtl32.dll' index 71;
function SharedMem9x_ReAlloc (ptr: pointer; size: cardinal) : pointer;  stdcall; external 'comCtl32.dll' index 72;
function SharedMem9x_Free    (ptr: pointer                ) : bool;     stdcall; external 'comCtl32.dll' index 73;
function SharedMem9x_GetSize (ptr: pointer                ) : cardinal; stdcall; external 'comCtl32.dll' index 74;

These functions are also exported from the winNT comCtl32.dll, but there they just point to LocalAlloc or something like that. So under winNT you have to use VirtualAllocEx, like Nick suggested.

Regards, Madshi.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2627364
Useful info, Madshi.
Will save it to use in future answers :)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2627393
:-)  Got it from this good site:

http://www.geocities.com/SiliconValley/4942/index.html
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:abondar
ID: 2627403
Hi Madshi!
I have not found these undocumented functions in comctl32.dll... Where they are??

Thanks,
 Anton.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2627409
It seems that they are exported by ordinal number.

For example, for SharedMem9x_Alloc:
GetProcAddress(hLib,LPCTSTR(71));
0
 

Author Comment

by:abondar
ID: 2627439
Hi Madshi!
I have not found these undocumented functions in comctl32.dll... Where they are??

Thanks,
 Anton.
0
 

Author Comment

by:abondar
ID: 2627441
Ahh... Ok, thanks!

Anton
0
 

Author Comment

by:abondar
ID: 2627481
Ahh... Ok, thanks!

Anton
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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