Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling an executable and waiting
Message
From
17/10/2003 07:40:20
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00839661
Message ID:
00839668
Views:
21
I have a PRG file which queries data. Once this has been done I want to open another executable (Not Foxpro) to carry out a task. When this task has been done I want to return the focus to my program again. Any help would be appreciated?
LPARAMETERS tcFileName
#DEFINE INFINITE  0xFFFFFFFF 

LOCAL ARRAY laJunk[1]
LOCAL lnRes, lcStartupInfo, lcProcInfo, lnHandle

*** Load DLLs if necessary
lnRes = ADLLS( laJunk )
IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'GetLastError', 1, -1, 1, 15 ) > 0)
  *** We don't have the function available
  DECLARE INTEGER GetLastError IN kernel32 
ENDIF
IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'CloseHandle', 1, -1, 1, 15 ) > 0)  
  DECLARE INTEGER CloseHandle IN kernel32 INTEGER nHandle
ENDIF 
IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'CreateProcess', 1, -1, 1, 15 ) > 0)  
  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 
ENDIF
IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'WaitForSingleObject', 1, -1, 1, 15 ) > 0)  
  DECLARE INTEGER WaitForSingleObject IN kernel32; 
          INTEGER hHandle, INTEGER dwMilliseconds 
ENDIF

***  The STARTUPINFO structure is used with the CreateProcess, 
***  CreateProcessAsUser, and CreateProcessWithLogonW functions 
***  to specify the window station, desktop, standard handles, 
***  and appearance of the main window for the new process.
lcStartupInfo = CHR(68) + REPLICATE(CHR(0), 67) 

*** The PROCESS_INFORMATION structure is filled in 
*** by the CreateProcess function with information 
*** about a newly created process and its primary thread.
lcProcInfo = REPLICATE(CHR(0), 16) 

IF CreateProcess( tcFileName, '', 0,0,0,0,0, CURDIR(),; 
                  lcStartupInfo, @lcProcInfo) # 0 

  *** retrieve handle for the new process by converting
  *** the first four bytes in the structure to a DWORD
  lnHandle = ASC(SUBSTR(lcProcInfo, 1, 1 ) ) + ; 
             ASC(SUBSTR(lcProcInfo, 2, 1 ) ) * 16^2 + ; 
             ASC(SUBSTR(lcProcInfo, 3, 1 ) ) * 16^4 + ; 
             ASC(SUBSTR(lcProcInfo, 4, 1 ) ) * 16^6 

  *** Now wait until it is finished
  WaitForSingleObject ( lnHandle, INFINITE ) 
  CloseHandle( lnHandle ) 
ELSE 
  MESSAGEBOX( 'Unable to Create Process' + CHR( 13 ) +;
              "Error code: " + TRANSFORM( GetLastError() ), 16, 'Major WAAHHHHH!!!!' )
ENDIF 
Previous
Reply
Map
View

Click here to load this message in the networking platform