Basic CURL with VB6

Posted On 2017-09-17 by dwirch
Keywords:
Tags: VB6 Complete Applications VB6 Windows API Windows
Views: 789

Title Uploaded Size
fphcurl.zip 9/17/2017 12:05:50 PM 2,500


This is a basic example of how to download the html of a web page with Visual Basic 6, using no ActiveX controls, and only Windows API calls.

Rather than utilizing a standard form-based interface for this example, I decided to build it as a more useful console application. Why a console app, you ask?

By utilizing a command line based application, you can more easily call the application from another scripting language, such as batch or PowerShell, and pipe the output to other locations, such as files or arrays.

Or, the gods forbid, you might have a pre-PowerShell Windows computer that is still in use, which you need to add this functionality to. This example might help you build a console based solution for a problem you might be having.

FPHCurl in action

Usage

Remember, this has no form-based interface, so all interaction is through the command line.  If you run this from the VB6 IDE, your screen will blink, but that is about it. To get any usable output from it, you'll have to compile it, and run it from the command line.  Don't forget to install the requirements before you compile it, though.  I you don't pay attention to requirements, this example won't make output!

The example only has one command line option, which is the URL for the website to grab. If you don't supply a URL, an error will be displayed.

Program Flow

This is a pretty basic demo. It doesn't do any parsing or anything, but simply grabs the HTML code of a website.

First, basic checks are made that a value was passed, and ensures that there is an HTTP:// or HTTPS:// in the front of the URL. Probably not necessary, but it's there. If it is not there, it is added.

Next, an attempt is made at downloading the HTML using the URLDownLoadA function in URLMon. If the URL is valid and accessible, the content is downloaded to a temporary file in the current directory. If the URL is not valid or accessible, Error 53 (file not found) is generated, and an error will be written to the console.

If the previous step has completed successfully, the content is output to the console, and the temp file is deleted.

Like I said, not much to it. Hopefully, someone can find some usage for this, maybe expand on it.

Special Instructions

Makes use of URLDownloadToFileA from URLMon to download HTML.

Requirements

This example requires the use of the outstanding VBAdvance console package for VB6, which allows you to create true console-subsystem applications in Visual Basic that interact with the command-prompt from which they were launched. This code module is the only one of it's kind and provides everything you'll need to create full-featured and robust console applications.

The package is available from:

http://vb.mvps.org/tools/vbadvance/

After the code is compiled, no external libraries or controls are needed. The reliance on the vbAdvance package is simply to make the console application. After the app is made, it's done.

No installation is needed, either.  Simply drop the executable somewhere in your path.


About the Author

has posted a total of 190 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.166.172.180

Before you can post, you need to prove you are human. If you log in, this test goes away.


Code Links