Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Skipping and dups when printing fillable pdfs
Message
 
To
23/03/2010 10:26:40
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01456159
Message ID:
01456850
Views:
242
Hi Debra,

if your application should wait for the called program to finish, then ShellExecute is the wrong function for this. The following program executes a command line, waits for the program to finish and returns the exit code:
*========================================================================================
* Executes another application, waits for it to complete and returns the error level
*========================================================================================
LParameter tcCmdLine

	*--------------------------------------------------------------------------------------
	* API declarations
	*--------------------------------------------------------------------------------------
	DECLARE INTEGER CreateProcess IN kernel32.DLL ;
		String lpApplicationName, ;
		STRING lpCommandLine, ;
		INTEGER lpProcessAttributes, ;
		INTEGER lpThreadAttributes, ;
		INTEGER bInheritHandles, ;
		INTEGER dwCreationFlags, ;
		String lpEnvironment, ;
		String lpCurrentDirectory, ;
		STRING @lpStartupInfo, ;
		STRING @lpProcessInformation
	Declare long GetLastError in Win32API

	*--------------------------------------------------------------------------------------
	* Launch the application
	*--------------------------------------------------------------------------------------
	Local lcStartupInfo, lcProcessInfo, lnOK
	lcStartupInfo = ;
		BINTOC(68,"RS") + ;
		Replicate(Chr(0),40) + ;
		BinToC(1,"RS") + ;
		BinToC(0,"2RS") + ; && SW_HIDE
		BinToC(0,"2RS") + ;
		Replicate(Chr(0),16)
	lcProcessInfo = Replicate(Chr(0),16)
	lnOK = CreateProcess( ;
		NULL, ;
		m.tcCmdLine, ;
		0, ;
		0, ;
		1, ;
		0x20, ;
		NULL, ;
		NULL, ;
		@lcStartupInfo, ;
		@lcProcessInfo ;
	)

	*--------------------------------------------------------------------------------------
	* Extract the handles from the PROCESSINFO structure
	*--------------------------------------------------------------------------------------
	Local lnProcessHandle, lnThreadHandle
	If m.lnOK == 0
		Return -1
	Else
		lnProcessHandle = CTOBIN(Substr(m.lcProcessInfo,1,4),"RS")
		lnThreadHandle = CTOBIN(Substr(m.lcProcessInfo,5,4),"RS")
	EndIf 

	*--------------------------------------------------------------------------------------
	* Wait for the process to terminate
	*--------------------------------------------------------------------------------------
	Declare Long WaitForSingleObject in Win32API Long, Long
	WaitForSingleObject( m.lnProcessHandle, -1 )
	
	*--------------------------------------------------------------------------------------
	* Get the error code
	*--------------------------------------------------------------------------------------
	Local lnExitCode
	lnExitCode = -1
	Declare Long GetExitCodeProcess in Win32API ;
	  Long hProcess, ;
  	Long @lpExitCode
	GetExitCodeProcess( m.lnProcessHandle, @lnExitCode )

	*--------------------------------------------------------------------------------------
	* Close handles
	*--------------------------------------------------------------------------------------
	Declare CloseHandle in Win32API Long
	CloseHandle( m.lnProcessHandle )
	CloseHandle( m.lnThreadHandle )

Return m.lnExitCode
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform