Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using Shell Execute
Message
From
30/01/2004 13:25:41
 
 
To
30/01/2004 12:40:47
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00872416
Message ID:
00872444
Views:
23
I think you should consider using automation instead, but if not, then the below code use createprocess works with Office XP. You will have to modify it for previous versions of Word though to look for the correct file in the correct location.
CLEAR

DO DECL

lcwordsparm = ""
lcwordsapp = "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"
lcwordsdir = LEFT(lcwordsapp,RAT("\",lcwordsapp)-1)
lcwordsprg = "WINWORD.EXE"
lcwordsdef = SYS(2003)
llwordok = .F.
SET DEFAULT TO LEFT(lcwordsapp,RAT("\",lcwordsapp)-1)
*--Does the app exist?
IF ADIR(laDummy, lcwordsapp)=1
   *--Can we run it?
   llwordok = RunAndWait(lcwordsprg, lcwordsparm, lcwordsdir)
   WAIT WINDOW "Finished Running Word 10"
ENDIF
RETURN

PROCEDURE  RunAndWait (lcApp, lcCmdLine, lcdir)
#DEFINE INFINITE  0xFFFFFFFF
LOCAL lcStartupInfo, lcProcInfo, hProcess, ;
	lnPrio, lnIBelieve1
lnIBelieve1 = 1   
lnPrio = 32 && Priority of Process=Normal
lcStartupInfo = CHR(68) + REPLI(CHR(0), 67)
lcProcInfo = REPLI(CHR(0), 16)
IF CreateProcess(0, m.lcApp+" "+m.lcCmdLine+CHR(0), 0,0,;
		m.lnIBelieve1, m.lnPrio,;
		0, 0, @lcStartupInfo, @lcProcInfo) <> 0
	* process and thread handles returned in ProcInfo structure
	hProcess = buf2dword(SUBSTR(lcProcInfo, 1,4))
	hThread = buf2dword(SUBSTR(lcProcInfo, 5,4))
	* waiting until the termination
	= WaitForSingleObject(hProcess, INFINITE)
	= CloseHandle(hThread)
	= CloseHandle(hProcess)
ELSE
	RETURN .F.
ENDIF

PROCEDURE DECL
DECLARE INTEGER CreateProcess IN kernel32;
	INTEGER lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,;
	INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,;
	INTEGER lpEnvir, INTEGER lpCurDir, ;
	STRING @lpStInfo, STRING @lpProcInfo
DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
DECLARE INTEGER WaitForSingleObject IN kernel32;
	INTEGER hHandle, INTEGER dwMilliseconds
RETURN

FUNCTION buf2dword(lcBuffer)
RETURN ASC(SUBSTR(lcBuffer, 1,1)) + ;
	ASC(SUBSTR(lcBuffer, 2,1)) * 256 +;
	ASC(SUBSTR(lcBuffer, 3,1)) * 65536 +;
	ASC(SUBSTR(lcBuffer, 4,1)) * 16777216
RETURN
>Hi All!
>
>I'm using shell exec to call MS Word from within form code. I want the code to stop executing until Word is closed, then continue on. I'm sure there's a way to do this and I may have done it before, but I can't remember what it is.
>
>Allen
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform