Return data to calling application.

BlitzMax Forums/BlitzMax Programming/Return data to calling application.

Hi. I call a BMax exe with B+ using ExecFile and i want to be able to tell the calling program that the BMax exe has finished what it is doing. Is there anyway to do this?

you should use this APIs:
OpenProcess (to start the 'child application')
GetExitCodeProcess (to check if it's running and, if ended, get the ending code).
OpenProcess returns a handler (Int of 32 bits), that can be passed as a parameter to GetExitCode to check if the appication is still running, and if it has exited, you can get also the exit code (errorlevel).
I don't have this API declaration statements now... I'll try to find them (I should have them somewhere...).

I don't know if ExecFile returns a process handler, if it does, you just need the API GetExitCodeProcess

Ok. Thanks very much!

Hi. I got the handle of the created process using CreateProcess but GetExitCode doesnt work. I tested it with notepad but when i closed it the GetExitCode retuned nothing at all.

What do you mean nothing at all? you mean a zero?
If it returns zero, it means the application has clossed well. diferent that zero, it means it has got some errors. (and the value is the errorlevel returned by the application).

OK i think i was getting a problem becasue i was using B+ (its in this forum because i though i had to do something within BMax originally) and i was using the B+ CreateProcess. So i've moved into Max now to keep within the rules :P and here is my code (the CreateProcess isn't even working now):

Extern "Win32"
	Function CreateProcess:Int(AppName:String,CommandLine:String,Security:Int,Thread:Int,Inherit,Flag:Int,Environ:Int,Dir:String,Startup,Process)
	Function GetExitCodeProcess:Int(Hnd:Int,Code:Int)
End Extern

Hnd = CreateProcess(Null,"C:/Windows/notepad.exe",Null,Null,False,Null,Null,Null,Null,Null)
Local Code:Int = 666

Repeat
	GetExitCodeProcess(Hnd,Code)
Until Code = 0

Print "End"


So would you be able to help me with this? Oh and the 666 is because i want it to exit the loop when the exit code is ok.

Trye declaring all strings to Byte ptr, and passing the string.ToCString as parameters, instead of the the strings.
I mean:
Function CreateProcess:Int(AppName:Byte ptr,CommandLine:Byte ptr,Security:Int,Thread:Int,Inherit,Flag:Int,Environ:Int,Dir:Byte ptr,Startup,Process)

and calling:
CreateProcess(AppNameVariable.ToCString(), CommandLineVariable.ToCString(), etc....)