45
Auto start/stop Visual FoxPro WWW Data Server

 

By Michael Drozdov

Summary

There is one problem using Microsoft Visual FoxPro 6.0 WWW Search Page Wizard when you need to start WWW Data Server manually (it serves data processing transmitted via Vfpcgi.exe working files). Here I will show how to avoid this problem.

To do it, you need to make some changes to Mycgi.c (…Vfp98/Tools/Inetwiz/Server/Mycgi.c), Server.scx screen form (WWW Data Server) and Server.prg located in Server.pjx project (…Vfp98/Tools/Inetwiz/Server/Server.pjx). The solution is to start WWW Data Server automatically upon receiving data request and auto stop it when idle time exceeds specified interval.


Changes in Mycgi.c:

To maintain WWW Data Server auto start make the following changes:

...
#include <sys/timeb.h>
#include <process.h>
#include <tchar.h>
...
#define SERVER_NODATA_TEXT_LOC "A server error occurred. No return data was sent."
#define WINVFPDATASERVER "WWW Data Server"
#define PRGVFPDATASERVER _T("C:\\Program Files\\Microsoft Visual Studio\\Vfp98\\Tools\\Inetwiz\\Server\\Server.exe")
void errorform( char *errorstring, char *errortitle );
BOOL IsVfpDataServer();
BOOL DoVfpDataServer();
...
	fpos_t pos;
	// Check and start VfpDataServer
	if (!IsVfpDataServer())
		DoVfpDataServer();
...
BOOL IsVfpDataServer()
{
	return (FindWindow(NULL, WINVFPDATASERVER) != (HWND)NULL);
}

BOOL DoVfpDataServer()
{
	BOOL bRetVal = FALSE;
	BOOL bResetDir = FALSE;
	TCHAR szCurDir[MAX_PATH];
	TCHAR szTmpDir[MAX_PATH];
	if (GetCurrentDirectory((DWORD)MAX_PATH, szCurDir) && 
			GetTempPath((DWORD)MAX_PATH, szTmpDir))
		bResetDir = SetCurrentDirectory(szTmpDir);
	bRetVal = _tspawnl(_P_DETACH, PRGVFPDATASERVER,
		PRGVFPDATASERVER, NULL) != -1;
	if (bResetDir)
		SetCurrentDirectory(szCurDir);
	return bRetVal;
}

Comments:


Changes in Server.prg:

To avoid error message upon passing parameters to parental process you need to add 3 formal parameters. They will not be used in the program.

...
#DEFINE ERRREC_LOC "Record number : "
LPARAMETERS tuUnk1, tuUnk2, tuUnk3
LOCAL lcProgram,lcFullPath,lnAtPos,lcFoxTools,lcError,lcFileName
...

Changes in Server.scx:

To maintain WWW Data Server auto stop make the next changes:

Add new property nLastEndProcess to Server.scx and set it’s default value to 0. Then make the following changes:

In the Init method:

ThisForm.nLastEndProcess = SECONDS()

In the Timer1.Timer method:

#DEFINE C_TIMEOUTSERVER_LOC 300 &&<- WWW Data Server timeout
#DEFINE C_ADDPROCESS_LOC "Adding process "
...
IF EMPTY(lcFileName)
	* Check Server timeout
	IF SECONDS()-ThisForm.nLastEndProcess > C_TIMEOUTSERVER_LOC
		ThisForm.cmdCancel.Click()
	ENDIF
	* Nothing waiting. Use normal delay.
	IF THIS.Interval != NORMAL_INTERVAL
		THIS.Interval = NORMAL_INTERVAL
	ENDIF
	RETURN
ENDIF
...
ThisForm.nLastEndProcess = SECONDS()

Known problems

The function DoVfpDataServer starts WWW Data Server hiddenly, so it may produce the following problems:

Problem Solution
The events protocol on WWW Data Server is inaccessible. Supply protocol events file from WWW Data Server
It’s not possible to stop WWW Data Server from Windows NT Task Manager. Find out PID of WWW Data Server in Windows NT Task Manager window and run the system utility “kill.exe <PID>”
 
 
Hosted by uCoz