Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with RUN command
Message
From
11/07/2000 10:33:31
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00390391
Message ID:
00390727
Views:
8
>>Another way - take ShellExecute route. I would recommend to take a look into Ed Rauh class and program.
>
>After I wrote this program and take a close look, I noticed two slight problems with this code.
>1) Check for type(tcCommandLine) should be at the top of routine, because why we need to declare all these functions, if we return 0?
>2) Each call of this function declares these functions again and again. May be it's nothing, but may be at 100th call we would have a memory blown. I vaguely recall Cetin Basoz asked a question, how can we check, if function is already Declared, but I don't remember the answers, he got...

Just create an additional property on the object called lLoadedDlls.

Create a method called LoadDlls and place all your DECLARES in that method and the last thing in the method would be lLoadedDLLs = .T.

Only call LoadDlls function when lLoadedDLLs is .f. to prevent repitiously declaring the functions.

Personally, when I need to use this function, I create the object, execute the method and then destroy the object...so there's never any repititous calls made to this function.

HTH

Jon

>
>Anyway, these are two potential problems with this code.
>
>>
>>

>>********************************************************************
>>* Description.......: LaunchAppAndWait
>>* Calling Samples...:
>>* Parameter List....:
>>* Created by........: Ed Rauh
>>* Modified by.......:
>>********************************************************************
>>FUNCTION LaunchAppAndWait
>>LPARAMETERS tcCommandLine, tuFromDir, tcWindowMode
>>
>>* tcCommandLine (R) - command line to launch
>>* tuFromDir (O) - Run from directory (default - CWD)
>>* tcWindowMode (O) - Start Application Window mode, one of (HIDE, MIN, MAX, NOR)
>>* (default - default setting of application)
>>
>>* Returns:
>>* 0 = CreateProcess didn't start what was asked
>>* 1 = Process ran to completion
>>* -1= Process started but user aborted wait. Danger - app is still running AFAIK
>>
>>#DEFINE cnINFINITE 0xFFFFFFFF
>>#DEFINE cnHalfASecond 500 && milliseconds
>>#DEFINE cnTimedOut 0x0102
>>
>>* We need some API calls, declare here
>>

Remove These to the LoadDlls method:

>>* GetCurrentProcess() returns the pseudohandle of the current process
>>DECLARE INTEGER GetCurrentProcess IN WIN32API AS GetCurrProc
>>
>>* WaitForIdleInput() waits until the target process is idle for input
>>DECLARE INTEGER WaitForInputIdle IN WIN32API AS WaitInpIdle ;
>> INTEGER nProcessHandle, ;
>> INTEGER nWaitForDuration
>>
>>* WaitForSingleObject() waits until the handle in parm 1 is signalled
>>* or the timeout period expires
>>DECLARE INTEGER WaitForSingleObject IN WIN32API AS WaitOnAppExit ;
>> INTEGER hProcessHandle, ;
>> INTEGER dwTimeOut
>>
>>* This API call does the work. The parameters are as follows:
>>* lpszModuleName - ptr-> file name of module to execute. Since we aren't launching .CPLs, do not use
>>* lpszCommandLine - ptr-> command to execute, as passed to us
>>* lpSecurityAttributesProcess - ptr-> SECURITY_ATTRIBUTES structure for Process. Pass a null pointer
>>* lpSecurityAttributesThread - ptr-> SECURITY_ATTRIBUTES structure for first thread. Pass a null pointer
>>* bInheritHandles - whether or not chlid inherits parent handles. Since no SECURITY_ATTRIBUTES passed, default to FALSE
>>* dwCreateFlags - Process Creation Mode flag set. We use the default mode at normal priority, ie 0
>>* lpvEnvironment - ptr-> a set of environment strings as if a MULTI_SZ. We don't set, so pass a null pointer
>>* lpszStartupDir - ptr-> the starting directory. If none provided to us, pass a null pointer
>>* lpStartInfo - ptr-> a STARTUPINFO structure. We use one structure member at times.
>>* lpProcessInfo - ptr-> a PROCESS_INFORMATION structure, used to return PID/PHANDLE detail.
>>* We use one member on return
>>DECLARE SHORT CreateProcess IN WIN32API AS CrPr ;
>> STRING lpszModuleName, ;
>> STRING @lpszCommandLine, ;
>> STRING lpSecurityAttributesProcess, ;
>> STRING lpSecurityAttributesThread, ;
>> SHORT bInheritHandles, ;
>> INTEGER dwCreateFlags, ;
>> STRING lpvEnvironment, ;
>> STRING lpszStartupDir, ;
>> STRING @lpStartInfo, ;
>> STRING @lpProcessInfo
>>
>>IF TYPE('tcCommandLine') # 'C'
>>
>> * Command line must be a character string
>> RETURN 0
>>
>>ENDIF
>>IF TYPE('tuFromDir') # 'C'
>>
>> * If not a character string, pass a null pointer, defaulting to Current Working Dir

IF ! THIS.lLoadedDLLs
THIS.LoadDlls()
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform