Receive SendMessage in VB 6.0

G

Guest

I need to send messages to a VB 6.0 exe with SendMessage (from a C++ app).
Anybody have sample code for a VB 6.0 message handler to receive SendMessage
or PostMessage commands?

Thanks.
 
K

Karen Kenworthy

<< I need to send messages to a VB 6.0 exe with SendMessage (from a C++
app).
Anybody have sample code for a VB 6.0 message handler to receive SendMessage
or PostMessage commands? >>

The safest trick is to send a seldom-used message for which VB defines a
form-level event handler. That way you can trap the message by just
handling the event. For example, you could send a WM_RBUTTONDOWN, showing
the <Ctrl> and <Alt> keys are pressed. In the form's MouseDown event
handler, look for this combo and execute your code if found.

You can subclass the form in VB6, allowing you to see the windows' messages
before VB does. Just call SetWindowLong with nIndex set to GWL_WNDPROC.
Pass the address of your new window procedure using the AddressOf keyword.

But be warned -- VB 6 programs that subclass forms (or any other window) are
inherently unstable. If they exit, while debugging or released, without
restoring the original Window procedure, Windows may crash afterwards.
Sending messages that trigger supported form events gets around that
problem.

Hope that helps.

Karen Kenworthy
http://www.karenware.com/
 
H

Herfried K. Wagner [MVP]

MCC said:
I need to send messages to a VB 6.0 exe with SendMessage (from a C++ app).
Anybody have sample code for a VB 6.0 message handler to receive
SendMessage
or PostMessage commands?

<URL:http://www.thescarms.com/vbasic/PassString.asp>

Note that this is a VB.NET newsgroup. VB6-related questions should be
posted to appropriate groups in the "microsoft.public.vb.*" hierarchy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top