C Program for Calling the Windows Version of TPL from another Windows
Program
/*
This sample C code demonstates how wtpl may be invoked from another
Microsoft Windows program. The code uses CreateProcess() to start
wtpl.exe and run the cps1.req example which is included with the
system.
The variable "path" should be set to where the system is
installed.
"args" may be changed if desired. See "The Script
Commands and Arguments" in TPL Help for an explanation of the
arguments.
As currently configured, this program runs wtpl in a visible mode.
To make wtpl run invisibly, change
si.wShowWindow = SW_SHOWNORMAL;
to
si.wShowWindow = SW_HIDE;
The procedure returns 0 if wtpl has been invoked successfully.
Otherwise it returns the Microsoft Windows error code.
*/
#include <windows.h>
#include <stdio.h>
static char *path = "c:\qqq\table\";
static char *args =
"%s TABLES -p %s\examples -r cps1.req -d cps.dat -f cps1.fmt -O 1";
int call_tpl(void)
{
BOOL rv;
PROCESS_INFORMATION pi;
STARTUPINFO si;
int last_error = 0;
char *program;
char *cmd;
program = malloc(strlen(path) + 20);
sprintf(program,"%swtpl.exe",path);
cmd = malloc(strlen(args) + strlen(program) +
strlen(path) + 20);
sprintf(cmd,args,program,path);
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
si.hStdInput = NULL;
si.hStdError = NULL;
rv = CreateProcess((LPCSTR)program,(LPTSTR)cmd,
NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
if (rv == 0)
last_error = GetLastError();
free((char *)program);
free(cmd);
return last_error;
}
|