Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Complex forms software to replace Delrina FF
Message
De
23/11/2004 13:15:23
 
 
À
23/11/2004 12:19:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00931761
Message ID:
00963948
Vues:
46
Hi Albert,

For troubleshooting, I think this is a bit easier:
doapp("c:\windows\notepad.exe","c:\myfile.txt")
RETURN

FUNCTION doapp 
LPARAMETERS cApptoRun, cCmdLine

DO DeclareDlls

cProcessInfo = Repli(Chr(0), 16)
cStartupInfo = CHR(68) + REPLICATE(CHR(0),67)
nCreationFlags = 0
cApptoRun = ALLTRIM(cApptorun)
cCmdLine = " " + ALLTRIM(cCmdLine)

nResult = CreateProcess(cApptorun, cCmdLine, 0,0,0,;
		nCreationFlags, 0, "C:\windows", @cStartUpInfo, @cProcessInfo)

IF nResult <> 0
	
	lnProcessHandle = Buf2dWord(SUBSTR(cProcessInfo,1,4))
	lnThreadHandle = Buf2DWord(SUBSTR(cProcessInfo,5,4))
	
	* wait until the termination of the program
	DOEVENTS

	DO WHILE .T.

      * reset exit code each loop
      STORE 0 TO ExitCode

      * fetch the exit code from the app
      =GetExitCodeProcess(lnProcessHandle,@ExitCode)

      * if exitcode = 259, this means app not busy so exit
      IF exitcode # 259  && not still busy
         EXIT
      ENDIF

      Sleep(100) && wait .1 seconds

	ENDDO

   CloseHandle(lnThreadHandle)
   CloseHandle(lnProcessHandle)
	
ELSE

   STORE GetLastError() TO lnErrorNum
   WAIT WINDOW "Last Error num: " + LTRIM(STR(lnErrorNum))

ENDIF

DO ReleaseDLLS

RETURN

*-----------------------------------------------------------
PROCEDURE Buf2DWord
PARAMETERS tcString
RETURN ASC(SUBSTR(tcString,1,1)) + ;
   ASC(SUBSTR(tcString,2,1)) * 256 + ;
   ASC(SUBSTR(tcString,3,1)) * 65536 + ;
   ASC(SUBSTR(tcString,4,1)) * 16777216 
   TO lnReturn

*-----------------------------------------------------------
PROCEDURE DeclareDLLS
LOCAL dllArray[1], lnNumDLLs

STORE ADLLS(dllarray) TO lnNumDLLs

IF ASCAN(dllarray,'CREATEPROCESS') = 0
	DECLARE INTEGER CreateProcess IN kernel32;
		STRING lpApplicationName, STRING lpCommandLine,;
		INTEGER lpProcessAttributes, INTEGER lpThreadAttributes,;
		INTEGER bInheritHandles, INTEGER dwCreationFlags,;
		INTEGER lpEnvironment, STRING lpCurrentDirectory,;
		STRING @lpStartupInfo, STRING @lpProcessInformation
ENDIF
IF ASCAN(dllarray,'GETLASTERROR') = 0
    DECLARE INTEGER GetLastError IN kernel32
ENDIF
IF ASCAN(dllarray,"CLOSEHANDLE") = 0
    DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
ENDIF
IF ASCAN(dllarray,"GETEXITCODEPROCESS") = 0
    DECLARE INTEGER GetExitCodeProcess IN WIN32API INTEGER hProcess, INTEGER @lpExitCode
ENDIF
IF ASCAN(dllarray,"SLEEP") = 0
    DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
ENDIF
RETURN

*-----------------------------------------------------------
PROCEDURE ReleaseDLLs  && release dlls for exewait function
CLEAR DLLS CreateProcess
CLEAR DLLS GetLastError
CLEAR DLLS CloseHandle
CLEAR DLLS GetExitCodeProcess
CLEAR DLLS Sleep
RETURN
From:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
.·*´¨)
.·`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"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform