project BLF > class Win32Lib > method ShellExecuteExtended
function returns integer
Description
Returns:
-1 wrong parameters
1 successfull
0 otherwise.
(do not forget to close the process handle)
Parameters
icFile | input | character | |
icParameters | input | character | |
icDir | input | character | |
icVerb | input | character | |
oiProcessHandle | output | integer | |
oiProcessId | output | integer | |
Internal usage
BLF
program code (program1/win32lib.p)
/* start with some error handling first */
empty temp-table tCBFError.
assign viCnt = 1.
if length(icFile, "CHARACTER":U) gt 255
then do:
create tCBFError.
assign
tCBFError.tiCBFSequence = viCnt
tCBFError.tcCBFMessage = substitute(
#T-1'The length of parameter &1 for calling ShellExecuteEx is too long.':255(5132)T-1#,
"lpFile":U)
viCnt = viCnt + 1.
create tCBFError.
assign
tCBFError.tiCBFSequence = viCnt
tCBFError.tcCBFMessage = quoter(icFile)
viCnt = viCnt + 1.
end.
if length(icDir, "CHARACTER":U) gt 255
then do:
create tCBFError.
assign
tCBFError.tiCBFSequence = viCnt
tCBFError.tcCBFMessage = substitute(
#T-3'The length of parameter &1 for calling ShellExecuteEx is too long.':255(5132)T-3#,
"lpDirectory":U)
viCnt = viCnt + 1.
create tCBFError.
assign
tCBFError.tiCBFSequence = viCnt
tCBFError.tcCBFMessage = quoter(icDir)
viCnt = viCnt + 1.
end.
if length(icVerb, "CHARACTER":U) gt 255
then do:
create tCBFError.
assign
tCBFError.tiCBFSequence = viCnt
tCBFError.tcCBFMessage = substitute(
#T-4'The length of parameter &1 for calling ShellExecuteEx is too long.':255(5132)T-4#,
"lpVerb")
viCnt = viCnt + 1.
create tCBFError.
assign
tCBFError.tiCBFSequence = viCnt
tCBFError.tcCBFMessage = quoter(icVerb)
viCnt = viCnt + 1.
end.
if viCnt gt 1
then do:
assign viReturn = -1. /* because -1 will never be returned by windows */
return viReturn.
end.
SET-SIZE (vmFile) = 256.
/*set the length of the parameters memptr dynamically*/
SET-SIZE (vmParameters) = length(icParameters, "CHARACTER":U) + 1.
SET-SIZE (vmDir) = 256.
SET-SIZE (vmVerb) = 256.
PUT-STRING(vmFile,1) = icFile. /*'cmd'.*/
PUT-STRING(vmParameters,1) = icParameters. /*'/c _progres.exe -b -p C:\Development\CBToolDistrib\test2.p >C:\Test\test.txt'.*/
PUT-STRING(vmDir,1) = icDir. /*'C:\Test'.*/
PUT-STRING(vmVerb,1) = icVerb. /*'open'.*/
SET-SIZE (vmExecute) = 60.
PUT-LONG(vmExecute, 1) = 60.
PUT-LONG(vmExecute, 5) = 64.
PUT-LONG(vmExecute, 13) = GET-POINTER-VALUE(vmVerb).
PUT-LONG(vmExecute, 17) = GET-POINTER-VALUE(vmFile).
PUT-LONG(vmExecute, 21) = GET-POINTER-VALUE(vmParameters).
PUT-LONG(vmExecute, 25) = GET-POINTER-VALUE(vmDir).
PUT-LONG(vmExecute, 29) = 0. /*1 for view, 0 for hidden*/
run ShellExecuteEx (input GET-POINTER-VALUE (vmExecute),
output viReturn).
oiProcessHandle = GET-LONG (vmExecute, 57).
SET-SIZE (vmExecute) = 0.
SET-SIZE (vmFile) = 0.
SET-SIZE (vmParameters) = 0.
SET-SIZE (vmDir) = 0.
SET-SIZE (vmVerb) = 0.
RUN getprocessid(oiProcessHandle, OUTPUT oiProcessId).
return viReturn.