Solved

Send message to the external application control

Posted on 2000-03-16
9
508 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Duplicates in Aggregate Query 3 39
Slow process to read Excel 15 120
Changing the installation path of this MSI 5 101
Need more details 5 148
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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