Article ID: 153904 - Last Review: October 23, 2003 - Revision: 3.1 How To Perform Background Processing in FoxProThis article was previously published under Q153904 On This PageSUMMARY
This article describes how to create a process to run another program in a
background of FoxPro using API routines and how to use some API calls
related to a process. The tasks described in this article are available as
commands in Microsoft FoxPro versions 3.0 and 3.0b.
NOTE: The following sample uses native Win32 applications. MORE INFORMATION
A Windows-based application that performs a long background task, such as
scanning serial ports, can be designed using Win32 API calls.
In FoxPro, the procedure code could be called in a timer method to facilitate checking for characters at semi-regular intervals. However, if large amounts of data are expected to be received from the serial port, this technique will reduce the chance of over-running the input buffer. This article discusses the code required to implement such a task in a separate module that can be executed in a background. The CreateProcess function is used to run a new program by creating a process. In addition to creating a process, CreateProcess also creates a thread object (a primary thread). The RUN command in FoxPro can be used to run a specified external MS-DOS program in a window. While the MS-DOS program or command is running, the title of the window is FoxPro Run Command. In FoxPro for Windows, after the external program or command is finished executing, the window title changes to Inactive FoxPro Run Command. The FoxPro for Windows menu system is disabled until this window is closed. In Visual FoxPro, the FoxPro Run Command window is closed after the external program or command is finished executing. In other words, FoxPro application does not have the control until the external program is finished executing. By using API calls, it is possible to run the specified external windows application in a background while the users have full control over their own FoxPro application. In this article, the customized API routine was written using Microsoft Visual C++ 4.0 to create a process and a thread. The following sample program illustrates the contents of the .DLL file written in Microsoft Visual C++ 4.0. It shows a way to create a process through the Win32 SDK. NOTE: This sample program illustrates many Microsoft Visual C++ commands. The use of these commands is beyond the scope of Microsoft FoxPro Product Support. Users with substantial experience using API routines should be able to write the following sample .DLL file. For this sample .DLL file to work, you need a .DEF file to export the disable function. Sample Program (DLL - to initiate a background program)Sample Program (DLL - to terminate the background program)Sample Program (FoxPro)Sample Program (Notes)
Furthermore, the backgrnd.dll creates the process in the separate address space with an unique process id and handle. After the process is created, you have access to your FoxPro program (your FoxPro and the C program (DLL) will run simultaneously). Once the process is created with the primary thread, the C program will run separately from the FoxPro application until you specifically ask it to terminate. A good way to terminate the process is when the user quits the FoxPro program. You should implement the terminat.dll code inside the last event of your project such as a Destroy event. This sample code is designed to work with only one process and will only work under Windows NT or Windows 95. | Article Translations
|

Back to the top
