Solved

Send message to the external application control

Posted on 2000-03-16
9
509 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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