Problem using CreateProcess
BlitzMax Forums/BlitzMax Beginners Area/Problem using CreateProcess
| ||
| Hi, i know how to use CreateProcess from C but now i wanted to use it from bm I wrote the following code, but it doesnt work. Can anybody give me a hint, what is going wrong?
Extern "Win32"
function CreateProcess ( lpApplicationName$z, lpCommandLine$z, ..
lpProcessAttributes, lpThreadAttributes, ..
bInheritHandles, dwCreationFlags, lpEnvironment, ..
lpCurrentDirectory$z, lpStartupInfo:Byte ptr, ..
lpProcessInformation:Byte ptr ) "WIN32" = "CreateProcessA"
function GetLastError:int () "WIN32"
end extern
type StartUpInfo
field cb:Int
field lpReserved:byte ptr, lpDesktop:byte ptr, lpTitle:byte ptr 'Pointer
field dwX:int, dwY:int, dwXSize:int, dwYSize:Int
field dwXCountChars:int, dwYCountChars:int
field dwFillAttribute:int, dwFlags:Int
field wShowWindow:short, cbReserved2:Short
field lpReserved2:Byte ptr 'PBYTE
field hStdInput:byte ptr, hStdOutput:byte ptr, hStdError:byte ptr
End type
type ProcessInformation
field hProcess:Int, hThread:Int
field dwProcessId:byte ptr, dwThreadId:byte ptr
end type
type TExecuter
field FName:String
field Parameters:String
field res:int, nhandles:Int
field handles:Int[2]
field StartInf:StartUpInfo
field ProInf:ProcessInformation
field lasterror:int
method New ()
StartInf:StartUpInfo = new StartUpInfo
StartInf.cb = sizeof(StartUpInfo)
print "Size"
print StartInf.cb
ProInf = new ProcessInformation
End Method
method Delete ()
StartInf = NULL
ProInf = NULL
End Method
method Execute (WaitForEnd:int)
local res:Int
local appname:String
res = CreateProcess ("","notepad.exe", NULL,NULL,TRUE,NULL,NULL,NULL,StartInf, ProInf)
print res
lasterror = GetLastError()
return(res)
end method
End type
local Ex:TExecuter = new TExecuter
ex.execute(false)
print ex.lasterror
|
| ||
This should do the trick,
Function CreateProcess ( lpApplicationName$z, lpCommandLine$z, ..
lpProcessAttributes, lpThreadAttributes, ..
bInheritHandles, dwCreationFlags, lpEnvironment, ..
lpCurrentDirectory$z, lpStartupInfo:Byte Ptr, ..
lpProcessInformation:Byte Ptr ) "WIN32" = "CreateProcessA@40"
"CreateProcessA@40" |
| ||
| Did you try it. Did it work? On my PC it has the same result as my version. CreateProcess returns a 0 and GetLastError returns that the file or path could not be found. No matter what program i want to start. |
| ||
| If you want to call notepad using only the commandlineparameter you must pass Null in the ApplicationName parameter. In your case ApplicationName isn't Null but instead an empty string which makes CreateProcess think that you want to launch Application "" with "notepad.exe" as commandline arguments... These should be valid variations... res = CreateProcess (Null,"notepad.exe", NULL,NULL,TRUE,NULL,NULL,NULL,StartInf, ProInf) res = CreateProcess ("c:\windows\notepad.exe","", NULL,NULL,TRUE,NULL,NULL,NULL,StartInf, ProInf) |
| ||
| Hi Sweenie, you where right. That was the thing that caused the problem. Thank you very much. |