Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to call a function in an exe file that is running

Status
Not open for further replies.

Phi1Smith

Programmer
Jun 5, 2001
33
0
0
GB
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.

Many Thanks

Phil
 
Try using Command line arguments throw command$
It is only an ideea, i do not know if it will worck for more that one function.

---------------------------------------------------------
Hope it will help.
 
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:
 
See also thread222-242879

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
 
If you make the running program an Active-X exe, you can call methods in it while it's running via normal COM calls (CreateObject, etc).

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top