Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RUN command in VFP 5.0 1

Status
Not open for further replies.

mhben

IS-IT--Management
Oct 13, 2000
3
US
I'm having trouble with the RUN command in VFP 5.0. I am attempting to call another windows app but I do not want the next line in my VFP program to execute until the called program has run and completed. I have tried to play with the PIF properties (checking "close on exit") for foxrun.pif. It seems that no matter what parms I include or exclude in the Run command the results are the same. I have also tried - RUN "start /w programxxx.exe" - but the /w wait parm hangs up the foxrun pif which requires user intervention to continue. If this makes sense to anyone out there and you have a tip on how I might solve this problem please let me know.

Thanks [sig][/sig]
 
mhben

Try substituting the following WinAPI call for your RUN command.

The called Windows application retains control until you close it.

It works under VFP6 but I can't vouch for VFP5.

* You will need to redefine lcProgram
lcProgram = ALLT(USER.editor);
[tab]+[ "];
[tab]+ALLT(SHEETS.filename);
[tab]+["] && Define lcProgram

#DEFINE NORMAL_PRIORITY_CLASS 32
#DEFINE IDLE_PRIORITY_CLASS 64
#DEFINE HIGH_PRIORITY_CLASS 128
#DEFINE REALTIME_PRIORITY_CLASS 1600
#DEFINE WAIT_TIMEOUT 0x00000102
#DEFINE WAIT_INTERVAL 200

DECLARE INTEGER CreateProcess IN kernel32.DLL ;
[tab]INTEGER lpApplicationName, ;
[tab]STRING lpCommandLine, ;
[tab]INTEGER lpProcessAttributes, ;
[tab]INTEGER lpThreadAttributes, ;
[tab]INTEGER bInheritHandles, ;
[tab]INTEGER dwCreationFlags, ;
[tab]INTEGER lpEnvironment, ;
[tab]INTEGER lpCurrentDirectory, ;
[tab]STRING @lpStartupInfo, ;
[tab]STRING @lpProcessInformation

DECLARE INTEGER WaitForSingleObject IN kernel32.DLL ;
[tab]INTEGER hHandle, ;
[tab]INTEGER dwMilliseconds

DECLARE INTEGER CloseHandle IN kernel32.DLL ;
[tab]INTEGER hObject

DECLARE INTEGER GetLastError IN kernel32.DLL

start = long2str(68) + REPLICATE(CHR(0), 64)
process_info = REPLICATE(CHR(0), 16)

File2Run = (lcProgram) + CHR(0)
RetCode = CreateProcess(0, File2Run, 0, 0, 1, ;
[tab]NORMAL_PRIORITY_CLASS, 0, 0, @start, @process_info)

IF RetCode = 0
[tab]=MESSAGEBOX("Error occurred. Error code: ", GetLastError())
[tab]RETURN
ENDIF

hProcess = str2long(SUBSTR(process_info, 1, 4))

DO WHILE .T.
[tab]IF WaitForSingleObject(hProcess, WAIT_INTERVAL) != WAIT_TIMEOUT
[tab][tab]EXIT
[tab]ELSE
[tab][tab]DOEVENTS
[tab]ENDIF
ENDDO

RetCode = CloseHandle(hProcess)

* Return to FoxPRO
ON ERROR DO ...

Hope does the trick

Chris [sig][/sig]
 
mhben

I omitted the following functions from the previous post.

You will need to put them in your procedure file.

*****
FUNCTION long2str
PARAMETERS m.longval
PRIVATE i, m.retstr

m.retstr = []

FOR i = 24 TO 0 STEP -8
[tab]m.retstr = CHR(INT(m.longval/(2^i))) + m.retstr
[tab]m.longval = MOD(m.longval, (2^i))
[tab]NEXT
[tab]RETURN m.retstr

*****
FUNCTION str2long
PARAMETERS m.longstr

PRIVATE i, m.retval

m.retval = 0
FOR i = 0 TO 24 STEP 8
[tab]m.retval = m.retval + (ASC(m.longstr) * (2^i))
[tab]m.longstr = RIGHT(m.longstr, LEN(m.longstr) - 1)
[tab]NEXT
[tab]RETURN m.retval

*****

Chris
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top