Solved

Send message to the external application control

Posted on 2000-03-16
9
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 20

Expert Comment

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

http://www.geocities.com/SiliconValley/4942/index.html
0
 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

738 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