Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Shellexecute()
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01569197
Message ID:
01569205
Vues:
84
J'aime (2)
Starting external program from VFP and waiting for its termination
http://www.news2news.com/vfp/?example=377
DO declare

*= RunAndWait("c:\windows\notepad.exe", "")
= RunAndWait("C:\program files\Microsoft Office\Office10\excel.exe", "")
* end of main

PROCEDURE RunAndWait(lcApp, lcCmdLine)
#DEFINE START_INFO_SIZE 68
#DEFINE INFINITE  0xFFFFFFFF
#DEFINE NORMAL_PRIORITY_CLASS 0x20

	LOCAL cStartupInfo, cProcInfo, hProcess, hThread
	cStartupInfo = PADR(Chr(START_INFO_SIZE), START_INFO_SIZE, Chr(0))
	cProcInfo = Repli(Chr(0), 16)

	IF CreateProcess(lcApp+CHR(0), lcCmdLine+CHR(0),;
		0,0,1, NORMAL_PRIORITY_CLASS, 0,;
		SYS(5)+SYS(2003), @cStartupInfo, @cProcInfo) <> 0

		* process and thread handles returned in ProcInfo structure
		hProcess = buf2dword(SUBSTR(cProcInfo, 1,4))
		hThread = buf2dword(SUBSTR(cProcInfo, 5,4))

		* waiting until the termination
		= WaitForSingleObject(hProcess, INFINITE)
	    = CloseHandle(hThread)
	    = CloseHandle(hProcess)
	ELSE
		? "Error code:", GetLastError()
	ENDIF

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

PROCEDURE declare
	DECLARE INTEGER GetLastError IN kernel32
	DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject

	DECLARE INTEGER CreateProcess IN kernel32;
		STRING lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,;
		INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,;
		INTEGER lpEnvir, STRING lpCurDir, ;
		STRING @lpStInfo, STRING @lpProcInfo

	DECLARE INTEGER WaitForSingleObject IN kernel32;
		INTEGER hHandle, INTEGER dwMilliseconds
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform