Importing an ActiveX control into Visual Basic (VB6)

This is a description of how to import an ActiveX control into Visual Basic 6. It is intended for users of the csXImage control but many of the principles apply generally to ActiveX controls and Visual Basic.

csXImage is supplied as an executable installation file (both the full and trial versions) and when this has been run it will unpack the files into the folder "c:\Program Files (x86)\Chestysoft\csXImage" or "...\csXImageTrial". It will also register the control. The important files are the control itself, csXImage.ocx or csXImageTrial.ocx, and the licence file, "csXImage.lic" or csXImageTrial.lic".

Some controls are supplied without an installer and then the .ocx file must be registered using the command line tool regsvr32.exe or with our utility DLLRegSvr.

To import the control into a Visual Basic project, open the project or create a new project and then open the Components dialogue by either selecting Projects and Components from the menu or right clicking on the Tool Box at the left hand side. (The shortcut CTRL + T will also work). The Components dialogue box lists components that are registered and it is simply a matter of finding the component on the list, which is in alphabetical order, tick the box, click Apply and then Close. The control icon appears in the Tool Box. For csXImage, the component name will be "csXImage Library" or "csXImageTrial Library".

Once imported, the control can be used in that project like any of the other controls in the Tool Box. As a quick test you can import a csXImage control and a button and run the following code in the button click event handler:

Private Sub Command1_Click()
  ImageBox1.LoadDialog
End Sub

The default name for a csXImage object when it is placed on a form is ImageBox1. This can be changed in the Properties box at the right hand side of the IDE. This code calls the LoadDialog command which allows the user to select and load an image from disk.

Licence Files (.lic)

csXImage is a licensed control, which means it is supplied with a licence file which is required at design time but not at run time. In the case of csXImage, it allows the control to be used in a project and then distributed royalty free, because the end user of the application is unable to create their own projects with the control because they have the .ocx file but not the .lic. A licensed control cannot be imported into a project unless the licence file is in the same folder as the .ocx file.

A problem can occur when an installation project is built using the VB Package and Deployment Wizard. If this installer is run on a machine that is being used for development it will copy the .ocx file into the Windows System32 folder and register it. When the project is next loaded into the VB IDE and error message will pop-up saying that the control is not licensed. This is because VB is looking for the .lic file in the wrong place. As a solution either register the control again using the .ocx file that is in Program Files, or move the .lic file to System32 so that it is at the same location as the .ocx. It is better not to test the installer on the development machine in the first place but to test it on a different machine.

32 bit and 64 bit versions

csXImage version 5.0 is supplied as two OCX files, one is 32 bit and the other is 64 bit. Both are registered and the files are copied into sub folders "\x86" and "\x64". Visual Basic 6 is 32 bit and so the 32 bit version of csXImage will be used, regardless of operating system.