Liquid Digital Lab

Why write an ActiveX control?

Posted 3 years, 2 months ago by Howard

Most people think of ActiveX as a web component - Quicktime player, Adobe Reader etc. are all available as ActiveX controls. This isn’t entirely true though, ActiveX is just a way of packaging an application so that it can be used in another application. You can write an ActiveX in many different languages, and the control you create can do anything that an ordinary installed application can do.

There are various reasons why you’d want to write your project as a control, rather than a standalone exe, but I’ll concentrate on the reason why I’d do it. ActiveX gives you the ability to embed VB code into an application written in a different language. For instance, Director is very good for producing attractive media and user interfaces, but is limited when it comes to other functionality. ActiveX allows you to insert anything you can do in VB, straight into a Director application. This makes it very useful for carrying out the backend work of our more complex applications.

This guide relates to programming in Visual Basic 6, and assumes that you have this installed and have some programming experience. It is oriented towards my usual use for ActiveX controls - as invisible plugins to Director.

What follows is not a complete beginners guide to writing an ActiveX - there are plenty of these available already online, and they’re better written than this and have pretty graphics too. This is more of a checklist of the steps you need to go through, and some little bits that weren’t in the beginners’ guides. Follow all the steps in order, as there are several bits that are a complete pain if you want to go back and change them later. For this reason you really need to have a plan of your project, and know before you start what controls it will use and what interfaces you want to expose.

Start a new ActiveX project

If you’re going to write an ActiveX, you need to start from scratch as an ActiveX project - don’t think that you can convert an existing project to an ActiveX. However, you can use any classes or modules in an ActiveX, so if you’ve structured your project well it will be simple to add the functionality you need from your existing project to your new ActiveX.

From the File menu, select “New Project” to get the New Project window open. Normally you’d just select the default “Standard Exe”, but this time choose “ActiveX Control”. A new project will be opened, it will look like a blank form just like a conventional project, but without the border.

Step 1 - Set a sensible name for your project, before you save anything. It’s much easier to do it now than to change it later.
From the project menu, select “Project 1 Properties”. Under the “General” tab, set Project name to something sensible. This will be the filename that that the project is saved under, and the pathname that is installed as by default.

In the Properties window for your control, change the Name field from “UserControl1″ to the name you want to call your control. This name is what your control will be referred to when it is added to a project, so it’s important that it is meaningful. Note that this can’t be the same as the project name.

Now you can save your project.

Add components to your ActiveX

Add any controls, references etc. that you will be using to the project. If you want to make any properties or methods of these controls accessible from outside the control, you need to add them before you create the interface. So it’s good practice to add everything you need at this stage.

Always add a background graphic to your control, even if the end user will never see it. Otherwise, it will appear as a blank square when you add it into the host project. Either make your graphic the correct size for your control, or resize your control to fit your graphic.

If you are making an invisible control for use in Director, make sure you set the following settings. This will prevent your control grabbing the focus and messing up the user experience.

Set Enabled to false
Set CanGetFocus to false
Set InvisibleAtRuntime to True

Create the interface

This is where you define the properties, methods and events that are exposed to the host application, not the visible interface that the user accesses on a control. It’s difficult to modify this afterwards, so make sure that you’ve planned for all the properties, methods and events you’re going to need before you start.

To create the interface, use the ActiveX Control Interface Wizard. To load this, use the “Add-Ins” menu, and select “Add-In Manager”. Select “VB 6 ActiveX Ctrl Interface Wizard” and check the “Loaded” checkbox.

The wizard is pretty self-explanatory, but here’s a few tips:

On the first page “Select Interface Members”, you can choose what properties of the control itself (effectively the main form of the control) are available to the host application. Remove everything - we’re making an invisible control so they are irrelevant.

On the next page you create all the interface members that you want to be accessible. Choose sensible names for these. They have to be legal function names, but if you use an invalid name it won’t warn you until after you close the wizard.

You can then choose to map the interface members directly to a control on your form - I never do this, as I almost always want to verify any input or output before passing it on.

Next, you set the attributes for each of your interface members. The return type and default value are pretty obvious, the Arguments setting is written in the same way as you would if you were creating a function. Always put something meaningful in the “Description” field. It’s optional, but it’s very helpful to the person will end up using your control.

When you finish the wizard you have the option to “View Summary Report”, this is worth reading as it explains how to create a test project for your ActiveX.

Write your code

I strongly recommend that you have your code already written at this point. Debugging the ActiveX can be a pain, so it’s good practice to have all your code tested and debugged in a standard exe, so that all you do now is add the classes and modules, and link these up to the interfaces you created.

If you open the code window for your control, you will see that the wizard has written the code to provide all the interfaces, so you just need to insert code to call your functions.

Compiling the Control

This is straightforward, and you compile the control in the same way you would a standard exe. You can also use the package and deployment wizard to create an installer package for distributing the control.

One thing you need to do once you’ve compiled the first version of the control, is set binary compatibility. This ensures that any updated versions of your control are drop-in compatible with the original version. If you don’t set this, and you update the control, you will have to update and recompile any application that uses your control.

From the project menu, select “Project Properties”. Under the “Component” tab, check “Binary Compatibility”.

Leave a Comment

Three D Clock

Classic clock built in processing

Posted by Lloyd - Comments (0)

This Happened #5

Lloyd gets chance to go along to the 5th gathering of This Happened

Posted by Lloyd - Comments (0)

Tom survives in one piece!

Tom makes it back to the office through 19 peaks over 149 miles, 60 flood warnings, 60mph gusts and 48hours of torrential rain, all in the name of MS Society, Wheels4Life and a weekend to remember!

Posted by Tom - 3 Comments (3)

Liquid goes Coast to Coast

Inspired by his managers previous fundraising wetsuit exploits, our newest designer Tom will be tackling the coast to coast bike ride this September.

Posted by Tom - Comments (1)

Liquid Artwork

Have a look at the artwork we created for the front office

Posted by Lloyd - 3 Comments (3)

Decisions, decisions… A Bit More Game AI

Game AI goes a few steps forwards, and 2000 years into the past…

Posted by Simon - 3 Comments (3)

Ever Won The Lottery?

Winning The Big One!
I recently read somewhere that winning the UK national lottery is easy. All you have to do is …

Posted by Simon - Comments (1)

3DS Max - Basics and Blueprints

The start of a series of tutorials in 3ds max from Liquids latest addition to the creative team.

Posted by Lloyd - 9 Comments (9)

Sound Reactive Sketch

We created this experimental Music Visualiser in processing & minim sound library.

Posted by Lloyd - 2 Comments (2)

Pathfinding in Games - Using A* in Director

Discover the joys of the A* pathfinding algorithm in our retro Director maze

Posted by Simon - Comments (1)

Colour Clock Screensaver

We’ve made an animated clock screensaver. You can have it too.

Posted by Ben - 2 Comments (2)

Using the Flash Tween Class

Trying to create realistic bouncing balls or elastic objects in Flash? Ben Stevens shows us the easy way to code motion using the Flash Tween Class.

Posted by Ben - 6 Comments (6)

A Jungle Jumble Using Lists in Director

What do you get if you cross a monkey, an elephant and a giant chicken-thing? Simon Edwards tries to explain using lists in Director.

Posted by Simon - 3 Comments (3)

Lloyd Survives the 2007 London Triathlon

Liquid’s very own budding triathlete successfully completes the Michelob ULTRA London Triathlon in a time of 2 hours and 42 minutes. Find out how he got on.

Posted by Lloyd - Comments (1)

Simple AI in Director

Simon Edwards discusses some of the techniques that developers call upon when programming games, particularly for defining logic that the computer will use for taking a turn in a 2-player game scenario.

Posted by Simon - Comments (0)

Ruby on Rails Tutorial - An Online DVD Catalogue

John Cove takes us through the process of making an online catalogue using RoR.

Posted by John - Comments (0)

Why write an ActiveX control?

Howard Peters discusses the advantages of using ActiveX, and explains how to create your own simple ActiveX control.

Posted by Howard - Comments (0)

Nichola’s Placement Year

Nichola, our resident student placement, has now been with us for a whole year and will be leaving us soon. So we asked her what it’s been like to work with the Liquid team.

Posted by Nichola - Comments (0)

Kinetica Soundwaves Exhibition

Exhibition visit

Posted by Ben - Comments (0)

PHP Tutorial - Creating a Quiz

John Cove explains how to use HTML and PHP to create an online quiz.

Posted by John - Comments (0)

Director Tutorial - Vector Font Outlines

Simon Edwards demonstrates an undocumented Director feature enabling you to map out a string of text in a vector cast member.

Posted by Simon - Comments (0)

HDR Photography

HDR (High Dynamic Range), is a software based, photographic technique that extracts tonal information from multiple exposures of the same shot. If you exposure bracket the same shot, you can merge all 3 images into one, then, using the data from all 3, create one output file which preserves accurate details from all exposures, bringing out highlights from the shadows.

Posted by Darren - Comments (0)

Happy Birthday To Us!

Liquid Digital Ltd has reached the end of its first financial year. There’s no time for cake and a candle though - there are some big things on the horizon for the first quarter of Year 2. Watch this space for news soon.

Posted by Simon - Comments (0)

Director Tutorial - Counting Down To A Launch Date

Tutorial written by our resident Director Guru, Simon Edwards.

Posted by Simon - Comments (0)

Lloyd in a wetsuit

Our creative leader will be braving the elements by competing in the Michelbob ULTRA London Triathlon on 4th August 2007.

Posted by Ben - Comments (0)