Program © 1998-2016 Guillaume Dargaud.
Free use and distribution.
Last updated on 2015/12/09
"First we thought the PC was a calculator. Then we found out how to turn numbers into letters with ASCII — and we thought it was a typewriter. Then we discovered graphics, and we thought it was a television. With the World Wide Web, we've realized it's a brochure." — Douglas Adams (1952—2001)
PanelToForm.exe is a very specialized tool: it takes a LabWindows/CVI 5.5 User Interface, generates an HTML page containing a <FORM> similar to it and at the same time it generates a C source file meant to interpret this form when submitted to a server. If you link this C source file to the application the UIR file is coming from, bang! you've got a LabWindows application that can respond directly to cgi-script requests. In other words, if you are not an experienced C programmer and website writer, you won't be interested in this tool.
OK, let's say we have a complete LabWindows/CVI application, Demo.exe, as defined in Demo.prj. It typically contains the user interface, Demo.uir, its declaration file, Demo.h, and the source code, Demo.c which contains the callback functions of the UIR and its own code.
Let's run this PanelToForm.exe on Demo.uir. It creates 2 files: Demo2html.html and Demo2c.c. The first is the HTML page containing the forms necessary for the cgi request, the second is a C source file to add to the Demo.prj project.
Let's take a look at the HTML file first. Each panel of the UIR is contained in a <FIELDSET>, all the panels being in the same <FORM>. When submitted, the form will call Demo.exe. Note: you need to set your server so that the directory containing Demo.exe and Demo2html.html has read and exe access so it can run scripts.
All the numeric controls have been transformed in <INPUT TYPE=text> boxes with the default value taken from the UIR file, the NAME of the control and the LABEL of the control (at this level, there is no distinction between int, double...). In a similar fashion:
Controls that are either dimmed or invisible or indicators are commented out (this is because they may get activated by software). I could have used DISABLED or READONLY too. You can modify the html and c file if you wish.
Now let's look at the other file generated by PanelToForm.exe: Demo2c.c. It is meant to be used with another C file: CGIC.C v1.06. You can find this small library at http://www.boutell.com/cgic/. CGIC is a C library designed to interpret cgi-scripts in a secure way. It provides a simple interface to the server and a set of functions to recover the values submitted by the form. It compiles easily in LabWindows/CVI, you just need to fill some declarations with (void), change
_CVI_DEBUG_ and add the following code:
#include <utility.h> #ifdef _CVI_DEBUG_ // we redirect the output to a file #define CGI_OUT_FILE "CgiOutput.html" #endif [...] #ifdef CGI_OUT_FILE cgiOut = fopen (CGI_OUT_FILE, "w"); #else cgiOut = stdout; #endif [...] cgiFreeResources(); #ifdef CGI_OUT_FILE fclose(cgiOut); #endif return result;
So add CGIC.C, CGIC.H and Demo2c.c to your original project. It should compile fairly easily (you may need to move some variable declarations as indicated in the source of Demo2c.c.
One important thing: remove or change the original
main() function of your code. In particular there won't be any call to
main() is now taken over by CGIC.C and the program's main function should be renamed
cgiMain(). I won't go in the details of the structure of a cgi application, you can read that in the documentation that comes with CGIC.C.
Let's just say that there is one function call per panel. The structure is more or less the same for each control: we call a secure function of CGIC.C to recover the value of the input form (if it exists), we set the value in the loaded panel, we call the corresponding callback function (if it exists) and we inform the client of the result with a
Something else: for cgi-scripts, you need programs that send back data to the standard output. Before CVI 5.5, LabWindows was using a special input/output window. So you can only use version 5.5, and set the option [Build][Target setting][Create Console application]. Also the program cannot be executed in debug mode. Or rather yes, it can, but through the Capture.exe program provided with CGIC.C (that you have to compile).
Now let's load this Demo2html.html page in a browser (not on a local disk, but really on an http server). Fill up some values like here and press one of the submit buttons. The two buttons at the bottom are added by default, this default [Submit] button allow you to submit the form if no other button is present on the original UIR.
After the submission, the exe indicated in <FORM> is called, the form analyzed, the server UIR updated, the real program ran through the callback calls, and the results sent back to the client. Sending back data to the client is up to you application. A few default output are sent back by the functions which read the form to confirm the values received, but you can send back a lot more. You can even create PNG files on the fly and <A REF> them or <IMG SRC> them. Use my ReadSavePng.fp function panel for this purpose.
You could even do better, you could link with the source code of PanelToForm, so that you can create on the fly a new form from an active panel (not one in a UIR file), and wait for the client response, and generate a new one... But for this you will have to buy my code.
Warning: This has not been extensively tested, so it's probably full of bugs. Check the code it generates thoroughly before feeding it to a cracker-packed WWW.
This freeware written with LabWindows/CVI.