Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Process Problems
Message
From
18/03/2004 16:05:13
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Create Process Problems
Miscellaneous
Thread ID:
00887680
Message ID:
00887680
Views:
60
I use createprocess api in other locations of my app fine. I am trying to instigate another use of it. Typically I use it run an .exe from my app and wait until the .exe closes and then return to my app. In this case, I want to do the same thing except the file I am running is not an .exe file but an .xfdf file. If you have Adobe Acrobat Reader installed and you have a .pdf file with form fields and a matching .xfdf file when you click on the .xfdf file in windows explorer Adobe Acrobat will launch and populate the form with the data from the .xfdf file. This works fine in windows explorer and in a dos window (except that the dos window is open also in that case).

Does createprocess work with non .exe files? Here is my code and it fails everytime:
lcACORDdef = SYS(5)+SYS(2003)
SET DEFAULT TO LEFT(hdir,RAT("\",hdir)-1)
*I can verify my default directory here is correct: c:\foxpro\vfp8
IF FILE(tempfile) .and. FILE(pdffile) && returns .t. as it should
*llacordok = RunAndWait(xacordform+'.xfdf',' ',LEFT(hdir,RAT("\",hdir)-1))
   *--line below is the same as the line above hard coded it for testing
   *--The only difference that I can see is that I am not passing a 2nd
   *--second parameter in this case (no command line)
   llacordok = RunAndWait('61NC.XFDF',' ','C:\FOXPRO\VFP8')
   IF !llacordok
	=MESSAGEBOX("Unable to print Acord Form.",0+16+4096,"ERROR")
   ELSE
	WAIT WINDOW "Finished Printing" NOWAIT
   ENDIF
ELSE
   =MESSAGEBOX("Unable to create Acord Form.",0+16+4096,"An ERROR Ocurred")
ENDIF
SET DEFAULT TO &lcACORDdef

RETURN

PROCEDURE  RunAndWait (lcApp, lcCmdLine, lcdir)
=DECL()
#DEFINE INFINITE  0xFFFFFFFF
LOCAL lcStartupInfo, lcProcInfo, hProcess, ;
	lnPrio, lnIBelieve1
lnIBelieve1 = 1   && Don't remember what that was
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
        *!!!* This is where it returns .f. the result is 0
	RETURN .F.
ENDIF
RETURN

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
.·*´¨)
.·`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"
Next
Reply
Map
View

Click here to load this message in the networking platform