Hi All,

how can i call an .exe file from a asm32 code? its possible to return the control to the caller after the called .exe finish?

Posted on 2002-04-01 19:35:57 by nestor
There is no such thing as control of code in multytask,
but you can know when the process you created exits.
Posted on 2002-04-01 19:46:49 by The Svin
Many thanks...and how can i know when the called process finish?

Posted on 2002-04-01 19:56:26 by nestor
invoke WaitForSingleObject,pi.hProcess,INFINITE

pi here PROCESS_INFORMATION struc, addr of wich you pass
with CreateProcess call
Posted on 2002-04-01 21:54:58 by The Svin
Don't use an INFINITE time period in your call to WaitForSingleObject, as your code will hang until the process being waited on finishes, and as your exe is hung your UI will be totally unresponsive. It is better to use a time period of 250 milliseconds (for example), that way you can still do stuff like respond to incoming messages (like user's keypresses or button clicks). Another benefit of using a finite time period is that you can time-out if the process does not end within a certain time.
Posted on 2002-04-01 22:39:10 by sluggy
Have a look at a procedure in the MASM32 library called "shell". Its designed to give you syncronous control when calling an external EXE file. Just note as the guys have already said that the calling app is dead until the called EXE file is finished.


Posted on 2002-04-02 04:17:12 by hutch--
Consider this logic in case you have GUI.
1. Create thread
2. In new thread CreateProcess
3. If OK new thread sends msg to main thread that new process created, so that that main thread could do anything it supposed to in the case.
4. Call in new thread WaitForSingleObject
5. When it returns - send message to main thread window that the process is done.
Posted on 2002-04-02 05:17:06 by The Svin
Thanks all of you. Just one last question about this,

- Can I use the same method in the called .exe to check if the calling app was killed? In that case, I want to shut down the called program. How can I do that? (check for the caller app...)

- How can I prevent to run directly the .exe without using first the caller?

(In the first case, the .exe was executed by the caller, in the second, the .exe is executed directly.)

Posted on 2002-04-02 05:18:13 by nestor
Make the called exe accept a command line argument, which could be just the process handle of the caller. The callee could then do a check of processes to see if the handle passed to it comes from the correct caller (if the handle is missing obviously the calle was not started by the caller). You can also use the handle to see if the caller is still running (use the process handle to set a WaitForSingleObject(), but then again didn't you want to do that in the caller as well, it would look pretty funny if two separate processes were waiting for each other to enter a signalled state).
Posted on 2002-05-04 06:58:26 by sluggy