Running an external program from an ASM running program [?]

Started by frktons, September 16, 2010, 01:30:28 PM

Previous topic - Next topic

frktons

Quote from: ToutEnMasm on September 16, 2010, 05:09:44 PM
Here a sample:
The called program can terminate or not with the end of the caller

invoke Execute_Independant_Win,NULL,NULL,SADR("notepad")



Well, thanks ToutEnMasm.

I don't want tha called program terminates the caller, so what have I to do
in order to return back to the caller?

Frank
Mind is like a parachute. You know what to do in order to use it :-)

ToutEnMasm


frktons

Quote from: ToutEnMasm on September 16, 2010, 05:20:21 PM
The called program is independant.Just close it


It doesn't work, with the example I've posted. I choose the prog, run it, but when
the called programs ends, the control is not given back to the caller.
Maybe I've done something wrong, or, as I guess, something else is missing.

Frank
Mind is like a parachute. You know what to do in order to use it :-)

ToutEnMasm


This depend where is the focus of the windows.
You can do that with the mouse (just click on the caller ) or with an API who move the focus on the caller.

ToutEnMasm


frktons

Quote from: ToutEnMasm on September 16, 2010, 05:28:30 PM

This depend where is the focus of the windows.
You can do that with the mouse (just click on the caller ) or with an API who move the focus on the caller.


If I call a WIN GUI program, it works, and the control goes back to the caller, no matter
where the focus is. But if I call a console prog, as I want to, the called prog terminates also the caller.

So there is something about the new console process to check, I guess.
 
Mind is like a parachute. You know what to do in order to use it :-)

ToutEnMasm


Your program is a console program.It is the normal way for them to close after they have done something.
Have a look on the example console program in the masm32 package.
Your interrogation of the keyboard isn't good.Nothing can be write.

frktons

Quote from: ToutEnMasm on September 16, 2010, 05:53:32 PM

Your program is a console program.It is the normal way for them to close after they have done something.
Have a look on the example console program in the masm32 package.
Your interrogation of the keyboard isn't good.Nothing can be write.


If you try to open a GUI program, after it finishes, the caller regains control, and
I close it when I want.
The problem is with other console programs, they inherit the same console, even
if I use INVOKE AllocConsole  in the called program.
The interrogation of the keyboard is done this way because I have only to halt
the flow, not getting any key for anything.


Mind is like a parachute. You know what to do in order to use it :-)

ToutEnMasm


This time i have found what is wrong.
Just put the ;.data? in comment or delet it and all things must run as you want.
You have a problem with bad init of variables.

frktons

Quote from: ToutEnMasm on September 16, 2010, 06:27:51 PM

This time i have found what is wrong.
Just put the ;.data? in comment or delet it and all things must run as you want.
You have a problem with bad init of variables.


OK, it works. But what is or are the bad declarations?
In the .data? no variable is initialized.  ::)
Mind is like a parachute. You know what to do in order to use it :-)

clive

; ml -coff -Fl -Zi cmdasm.asm -link /SUBSYSTEM:CONSOLE

        .386

.nolist
include \masm32\include\masm32rt.inc
        .list

        .data

cmdfn   db      "notepad cmdasm.asm",0

        .code

_start:

        invoke crt_system, ADDR cmdfn

print str$(eax), 9, "returned by crt_system", 13, 10

        invoke ExitProcess, eax

        ret ; paranoia

        end _start
It could be a random act of randomness. Those happen a lot as well.

frktons

Quote from: clive on September 16, 2010, 07:01:08 PM
; ml -coff -Fl -Zi cmdasm.asm -link /SUBSYSTEM:CONSOLE

        .386

.nolist
include \masm32\include\masm32rt.inc
        .list

        .data

cmdfn   db      "notepad cmdasm.asm",0

        .code

_start:

        invoke crt_system, ADDR cmdfn

print str$(eax), 9, "returned by crt_system", 13, 10

        invoke ExitProcess, eax

        ret ; paranoia

        end _start


Thanks clive. his is good as well.  :U

I'm trying to find out what's wrong with one of these declarations:

    StartUpInfo  STARTUPINFO <>
    ProcessInfo  PROCESS_INFORMATION <>   


because when I added them to call:


    invoke memfill,ADDR StartUpInfo,SIZEOF StartUpInfo,0 ; fill STARTUPINFO
   
    mov StartUpInfo.cb,SIZEOF StartUpInfo ;

    INVOKE CreateProcess,DWORD PTR PtrFileName,0,0,0,0,0,0,0,ADDR StartUpInfo,ADDR ProcessInfo


the program doesn't return back from calling a console program, but only when
I call a GUI program it works fine.

Do you guess why?

Frank
Mind is like a parachute. You know what to do in order to use it :-)

jj2007

Quote from: frktons on September 16, 2010, 04:56:31 PM
Quote from: jj2007 on September 16, 2010, 04:42:22 PM
:wink
QuoteLaunch
   Launch "Notepad.exe"
   Launch "Notepad.exe MyNewFile.txt"
   Launch "Notepad.exe MyNewFile.txt", SW_MINIMIZE
   Launch "Notepad.exe MyNewFile.txt", SW_MAXIMIZE, 2000   ; cmd, show, timeout in ms
Rem[/color]   returns CreateProcess error code in eax
[/b]

Hi Jochen. This other one is quite new for me.  ::)

What is it? A MACRO? A function? Or what? Where do I find the documentation?

It's Basic. Or Masm? Who knows ::)

frktons

Quote from: jj2007 on September 16, 2010, 08:01:39 PM
It's Basic. Or Masm? Who knows ::)

It is not MASM, it is not BASIC, it is not a MASM32 MACRO.
mmmmmmmhhhhhhhhhh!!!!!
Well it should be Superman  :lol
Mind is like a parachute. You know what to do in order to use it :-)

Tedd

Quote from: frktons on September 16, 2010, 04:56:31 PM
Well an example speaks more than 1000 words.
Here it is the complete prog, so why it closes when back from the
called prog? I surely need some other instructions, like  WaitForSingleObject [hProcess],
how and where I put it in the following code?
Checking the API documentation is a useful skill. Things become much clearer when you actually try them out.



INVOKE CreateProcess,DWORD PTR PtrFileName,0,0,0,TRUE,0,0,0,ADDR StartUpInfo,ADDR ProcessInfo
;return value is a handle to the created process (assuming it succeeds)

mov hProcess,eax   ;save it for future use

INVOKE WaitForSingleObject, hProcess,-1

;your program now waits for the process to finish,
;returning to this point when it has exited

Also, setting bInheritHandles=TRUE means the process uses the parent's console.
No snowflake in an avalanche feels responsible.