Basic CURL with VB6

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

Download Attachment

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.


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.


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:

About the Author

dwirch has posted a total of 185 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:

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

Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers