feed   myspace   facebook   last.fm   send an email   twitter   tumblr   send a message via aim to graykicksass

Posts tagged ‘cgi-bin’

Writing webapps in QuickBasic 4.5

Disclaimer: I realize this has no real valuable use whatsoever.

First off, credit where credit is due, when I initially had to setup the CGI I ran into a problem solved buy a guy on reddit, who managed to write a website clone in quickbasic. You have to do a simple C++ stub app that can direct the output from quickbasic apps into the server.

In order to pull this off, you’ll need a copy of the following tools:
1. Dev C++ (For compiling the stub app, to make your life easier, grab the one with a compiler built into the install) here

2.Quickbasic 4.5 (capable of generating EXE files) here

I also recommend xampp, very quick installation, works perfectly for this example. Grab it here


Now, to actually install quickbasic from this zip on windows, you have to create a fake A drive, or copy the files to a floppy.

The trick to doing this is a command line trick called subst

So, copy the quickbasic disk1 folder from the download, place it in a folder on C: like, FLOPPY1 and run this:
subst a: C:\FLOPPY1

Run the quickbasic setup app on the fake disk, when prompted to insert another disk, copy the contents of disk2 into the fake drive. Hopefully you’ll be able to run quickbasic now, and be greeted by this screen:

QuickBasic 4.5 welcome screen

QuickBasic 4.5 welcome screen

Once your in quickbasic, navigate the menus with ALT or your mouse, type out this simple program:

PRINT “Content-Type: text/html”
PRINT “”
PRINT “”
PRINT “
<h1>Hello World!</h1>

PRINT “”

Move over to the run menu and hit make EXE file, save your app. The app will be in the saved file directory, take it, rename it something simple (e.g. ‘app.exe’) and close.

Now, open up dev C++, navigate to File->New->Project and select console application, select C++ for the language, copy and paste this code into main.cpp:

#include <iostream>
#include <string>
#include <stdio.h>
int main(int argc, char *argv[])
{
std::string piper;
FILE* data = popen(“app.exe”,”r”);

for(char c = getc(data);c != EOF;c = getc(data))
{
piper.push_back(c);
}
pclose(data);

std::cout << piper;
return 0;
}

Press ctrl+F9 to compile or select compile from the menu. Open the directory where you saved the project, and copy the generated EXE file over to your cgi-bin directory (in htdocs for apache, with xampp it’s in the root directory of xampp/cgi-bin).

Now, with the stub in cgi-bin, rename your compiled quickbasic app to ‘app.exe’, and copy it to cgi-bin. Navigate to http://localhost/cgi-bin/stub.exe where stub.exe is whatever your compiled C++ application is called, you should now see a screen something like this:

hello world from quickbasic

hello world from quickbasic

Now you can run your webapps and display output in the browser, all you need now is to parse CGI variables, which is done via the ENVIRON$ function.

PRINT “Content-Type: text/html”
PRINT “”
PRINT “”
PRINT “
<h1>Hello World!</h1>

PRINT ENVIRON$(“QUERY_STRING”)
PRINT “”

QUERY_STRING is set by the CGI gateway, accessing this page with a url like http://localhost/cgi-bin/qload.exe?bla would print:
“Hello World! bla”

This has no real practical use anymore, but it’s just interesting to try out. Also, sorry about the code blocks here being screwed up, wordpress managed to mangle them.