Using the Chilkat ActiveX in Visual Basic 6
add a reference once, then use Chilkat classes like any other VB6 object
Windows · Visual Basic 6.0 (always 32-bit) · Chilkat ActiveX v11
The Chilkat ActiveX is a COM library: your VB6 code creates Chilkat objects such as ChilkatHttp,
ChilkatJsonObject, or ChilkatCrypt2 and calls their methods. That gives a VB6 program
HTTP/REST, email, FTP/SFTP, Zip, PDF, encryption, digital signatures, JSON, XML, and the rest of the Chilkat API.
Chilkat objects have no user interface; you create them in code rather than placing them on a form.
The 60-second version
- Install the 32-bit Chilkat ActiveX, even on 64-bit Windows. VB6 programs are always 32-bit.
- In VB6 choose and check Chilkat ActiveX v11.x.x.
- Write
Dim http As New ChilkatHttpand call its methods. - When you distribute your program, install and register the 32-bit Chilkat ActiveX on each computer.
On this page: Install Add the reference First program JSON into a list Events & async VB6 tips Deploying Troubleshooting
Setup
Install the 32-bit Chilkat ActiveX
The VB6 IDE and every program it compiles run as 32-bit processes, so they can only load the 32-bit Chilkat ActiveX. The 64-bit ActiveX is invisible to VB6, even on 64-bit Windows.
| Installer | Use it when |
|---|---|
| Per-machine | Recommended for VB6. Registers Chilkat for every user of the computer and requires administrator rights. If you run the VB6 IDE as administrator, as many developers do on current Windows, use this one: an elevated process doesn't use per-user COM registrations. |
| Per-user | Registers Chilkat only for the current Windows user and normally needs no administrator rights. Works when the IDE and your program run as that user without elevation. |
The ActiveX download page also has ZIP downloads with a register.bat
script that registers the DLL with regsvr32. Keep the DLL on a local drive, not a network share. The downloads
are the full version and are fully functional for a 30-day
evaluation.
Add a reference to the Chilkat ActiveX
In the VB6 IDE choose , scroll to Chilkat ActiveX, check it, and click OK. The entry's name includes the Chilkat version you installed. The reference gives you IntelliSense for every class, method, and property, and the F2 Object Browser shows the whole API.
Use Project » References, not Project » Components. Chilkat classes are created in code with
New or CreateObject. If you also add Chilkat under Components and drag objects onto a form,
VB6 reports Invalid use of New keyword. See VB6 Invalid Use of New
Keyword.
You can also use Chilkat without a reference (late binding): declare the variable As Object and create it
with CreateObject("Chilkat.Http"). The ProgID is Chilkat. plus the class name without the
Chilkat prefix, for example Chilkat.JsonObject for ChilkatJsonObject. Late binding
loses IntelliSense and compile-time checking, so most VB6 programs use the reference.
Examples
Your first program: unlock Chilkat and fetch a URL
Chilkat must be unlocked once per process with UnlockBundle. During the 30-day trial any string works;
after purchase, use your license code. Put this helper in a standard module () so every form can call it:
' Module1.bas -- unlocks Chilkat once per process. Returns True when Chilkat is ready.
Public Function ChilkatReady() As Boolean
Static unlocked As Boolean
If Not unlocked Then
Dim glob As New ChilkatGlobal
unlocked = (glob.UnlockBundle("Anything for 30-day trial") = 1)
If Not unlocked Then MsgBox glob.LastErrorText
End If
ChilkatReady = unlocked
End Function
Then add a command button to a form and paste this into the form's code:
Private Sub Command1_Click()
If Not ChilkatReady() Then Exit Sub
Dim http As New ChilkatHttp
Dim s As String
s = http.QuickGetStr("https://www.chilkatsoft.com/helloworld.txt")
If http.LastMethodSuccess <> 1 Then
MsgBox http.LastErrorText
Exit Sub
End If
MsgBox s
End Sub
Press F5 and click the button. A message box shows Hello World!.
Load JSON from a web request into a ListBox
This handler downloads a small JSON document, parses it with ChilkatJsonObject, and adds each member to a
ListBox named List1. The same pattern works for any REST API: send the request with ChilkatHttp
or ChilkatRest, then read the fields with StringOf, IntOf, and
SizeOfArray.
Private Sub Command2_Click()
If Not ChilkatReady() Then Exit Sub
' {"apple":"red", "lime":"green", "banana":"yellow", ...}
Dim http As New ChilkatHttp
Dim jsonText As String
jsonText = http.QuickGetStr("https://www.chilkatsoft.com/exampledata/sample.json")
If http.LastMethodSuccess <> 1 Then
MsgBox http.LastErrorText
Exit Sub
End If
Dim json As New ChilkatJsonObject
If json.Load(jsonText) <> 1 Then
MsgBox json.LastErrorText
Exit Sub
End If
List1.Clear
Dim i As Long
For i = 0 To json.Size - 1
List1.AddItem json.NameAt(i) & vbTab & json.StringAt(i)
Next i
End Sub
Progress events and asynchronous methods
Chilkat classes that do long operations raise events such as PercentDone, AbortCheck, and
ProgressInfo. To receive them, declare the object WithEvents at the module level of a form or
class module (not inside a procedure):
Private WithEvents m_http As ChilkatHttp
Private Sub Form_Load()
Set m_http = New ChilkatHttp
End Sub
Private Sub m_http_PercentDone(ByVal percent As Long, abort As Long)
Label1.Caption = percent & "%"
DoEvents
' Set abort = 1 to cancel the operation.
End Sub
Events are raised on the same thread as the call, while the method is still running. Keep handlers short. For
background work, Chilkat's ...Async methods return a ChilkatTask that runs on its own thread;
read VB6 Event Callbacks before using them, because VB6 objects must not be called
from a background thread. A program that uses any Async method must call
FinalizeThreadPool before it exits, or the VB6 IDE can crash on exit.
Things to know when calling Chilkat from VB6
Chilkat returns 1 or 0, not VB6's True/False. Chilkat ActiveX methods that report success, and properties such as
LastMethodSuccess, return a Long: 1 for success and 0 for failure. VB6's
True is -1, so compare with 1:
- Correct:
If success <> 1 Then… orIf success = 0 Then… - Wrong:
If success = True Thenis never true, because 1 is not -1. - Also wrong:
If Not success Thentreats success as a failure too. On aLong,Notis a bitwise complement:Not 1is-2, which is nonzero.
| Topic | What to do |
|---|---|
| Errors | Chilkat doesn't raise VB6 errors for ordinary failures. Check the return value (or
LastMethodSuccess for methods that return a string or object) and read LastErrorText, which
explains exactly what went wrong. While debugging, Debug.Print obj.LastErrorText writes it to the Immediate
window. |
| Unlocking | Call UnlockBundle once per process, for example in Sub Main or the
startup form's Form_Load. Calling it again is harmless. |
As New | Dim x As New ChilkatHttp creates the object the first time it's used, and
re-creates it if you set it to Nothing and use it again. If you prefer explicit creation, write
Dim x As ChilkatHttp and then Set x = New ChilkatHttp. |
| Object lifetime | Objects are released when the variable goes out of scope. Use Set obj = Nothing
to release one earlier, for example a connection you are finished with. |
| Unicode text | VB6 strings hold Unicode, and Chilkat receives and returns Unicode strings. The standard VB6
controls, however, display text in the system's ANSI code page, so characters outside it can appear as ?
in a TextBox even though the string itself is correct. Write the text to a file with Chilkat (for example
ChilkatStringBuilder.WriteFile with "utf-8") to check it. |
| Binary data | Methods that return bytes return a Variant containing a byte array. Assign it to a
Variant or a Byte() array. For large data, ChilkatBinData keeps the bytes inside
Chilkat and avoids copying. |
| Long operations | The form doesn't repaint while a Chilkat call runs. Set timeouts such as
ConnectTimeout and ReadTimeout where a class has them, and use events or async tasks for long
transfers. |
| Chilkat v9.5 code | v11 ProgIDs are Chilkat.Http, Chilkat.Global, and so on. Older
v9.5 code uses Chilkat_9_5_0.Http and a Chilkat ActiveX v9.5.0 reference. Both versions can be
installed side by side; see Chilkat ActiveX v11 and v9.5 on the same
computer. |
Deploying a VB6 program
Your EXE doesn't contain Chilkat; it finds the Chilkat ActiveX through the Windows registry. On each computer where the program runs:
- Install and register the 32-bit Chilkat ActiveX. The simplest way is to run Chilkat's 32-bit per-machine MSI from your setup, or to have your installer copy the DLL and register it (most installer tools can register COM DLLs).
- If you register the DLL yourself on 64-bit Windows, use the 32-bit
regsvr32:C:\Windows\SysWOW64\regsvr32.exe. The ActiveX DLL Registration Tutorial explains the 32-bit and 64-bit registries. - Install the DLL to a local folder and don't move it after registering, because the registry records its path.
Troubleshooting
| Message | Cause and fix |
|---|---|
| Run-time error '429': ActiveX component can't create object | The 32-bit Chilkat ActiveX isn't registered on this computer, or it is registered per-user and the program runs
elevated or as another user. Install the 32-bit per-machine MSI. With late binding, also check the ProgID spelling
(Chilkat.Http). |
| Compile error: User-defined type not defined | The Chilkat reference isn't checked. Check Chilkat ActiveX in . |
| MISSING: Chilkat ActiveX… in the References dialog | The project was saved on a computer with a different Chilkat installation. Uncheck the missing entry and check the current Chilkat ActiveX. |
| Compile error: Invalid use of New keyword | Chilkat was added under as well as References. See VB6 Invalid Use of New Keyword. |
| Run-time error '438': Object doesn't support this property or method | The method or property name is misspelled, or the installed Chilkat version is older than the one the code was written for. Check the name in the reference documentation. |
| The IDE crashes when you close it | The program used an Async method without calling FinalizeThreadPool
before exiting. |
| A Chilkat method returns 0 or an empty string | The operation itself failed (a network error, a bad password, an invalid file path, and so on). Show
LastErrorText; it names the cause. |
Next Steps
- 📖 Chilkat ActiveX Reference Documentation — every class, method, and property
- 💻 Chilkat VB6 examples — thousands of ready-to-run examples
- 📦 Chilkat ActiveX downloads (MSI installers and ZIP files)
- ✉ Contact Chilkat support
Visual Basic is a trademark of the Microsoft group of companies.