Hi
I'm looking for a way to call a function or a sub within an already running EXE file. The running EXE is a program of mine so I know all the names of the functions and I could rewrite the code if required.
I would recommend using SendMessage of the WM_COPYDATA type as it is about the best, lightweight IPC (interprocess communmication) facility. This really only works for you when you are coding both the sending and receiving applications. But, since it is a Win32 messaging standard the sending (driving) "application" can be just about anything, including a console app, DLL, VB app, Win32 GUI app, etc. And, the "driven" or receiving application can be anything that has a message loop, including a VB app or Win32 app. As I said, the only requirement is that you are coding both sides of the equation.
In a nutshell, this is what you have to do:
Calling Application:
---------------------
1. The calling application must find the window handle of the receiving application.
2. The calling app must set up a COPYDATA buffer to send to the receiving application. Use the following struct for this buffer:
Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As Long
End Type
Note that dwData can be any constant (1, 2, 3, etc) and used by you and your program for controlling execution as different constant values can force your receiving program to execute different functions, etc.
3. The calling application using SendMessage to send the WM_COPYDATA message and its payload.
Receiving Application:
----------------------
1. The receiving applicaton must hook the main window proc so it can receive all the window messages. In particular, it needs to do its own processing of WM_COPYDATA.
2. When processing the WM_COPYDATA message, the receiving application can do anything you program it to, based on the
.dwData value it gets.
I have used this technique several times in the past with much success.
See the following MS Q article for much more information on this subject:
Strongm has an excellend post on how to hook the ProcWindow for the receiving application.
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.