Visual Basic 6 applications are still shipping, still selling, and still worth protecting. KeyNub supports VB6 through a COM server — not a set of Declare statements — .
Why a COM Object and Not Declare Statements
The KeyNub core library exposes a flat C API using the cdecl calling convention. VB6’s Declare statement emits stdcall. In a 64-bit process this distinction does not exist, so the VBA binding works in 64-bit Office. In a 32-bit process — and VB6 is always 32-bit — neither side pops the arguments off the stack, so the stack pointer drifts a little with every call until something falls over, somewhere else, much later.
VB6 has a CDecl keyword, but it is documented as Macintosh-only and is ignored on Windows. So there is no correct way to call a cdecl library from VB6 with Declare. COM removes the problem entirely: the type library describes the contract, and the marshaller handles the call.
You also get three things:
- The object owns the dongle. If an early
Exit Subskips yourClosecall, releasing the reference closes it anyway. No leaked handles. - Real error messages. Failures raise with
Err.Descriptioncarrying the SDK’s own diagnostic text, not “Automation error”. - Byte arrays are just Byte arrays. The interface uses SAFEARRAYs, which is what a VB6
Byte()already is. No pointer arithmetic, noCopyMemory.
Installing
Register the DLL once, using the regsvr32 that matches its architecture. VB6 is 32-bit, so on 64-bit Windows that is the one in SysWOW64:
C:\Windows\SysWOW64\regsvr32.exe KeyNub.dllCode language: Bash (bash)
The type library is embedded in the DLL as a resource, so there is one file to deploy and registration-free (side-by-side) activation also works if you would rather not touch the registry on customer machines. An unelevated regsvr32 falls back to a per-user registration instead of failing.
A wrong-bitness DLL reports “class not registered”, which reads like a registry fault and is not. If you see that, check the architecture first.
Reading a License
Late binding, so it runs with no project references configured:
Dim dongle As Object
Set dongle = CreateObject("KeyNub.Dongle")
' No dongle plugged in is a normal situation, not an error. Ask first.
If dongle.DeviceCount = 0 Then
MsgBox "Please plug in your KeyNub license dongle."
Exit Sub
End If
dongle.Open "" ' first dongle found; pass a serial to pick one
If Not dongle.IsGenuine Then
MsgBox "This dongle is not a genuine KeyNub."
Exit Sub
End If
dongle.SessionOpen ' encrypted session, required before records
Dim license() As Byte
license = dongle.RecordRead("license")
dongle.CloseCode language: VB.NET (vbnet)
For early binding, add the KeyNub License Dongle reference to your project and declare Dim dongle As New KeyNub.Dongle. You then get IntelliSense and the object browser, because every member carries a help string.
Handling Errors
Failures raise. The numbering is stable and documented, so you can branch on it:
On Error GoTo Failed
dongle.SessionOpen
Exit Sub
Failed:
' Err.Number is vbObjectError + 5000 + the SDK status code.
MsgBox "KeyNub error " & (Err.Number - vbObjectError) & _
": " & Err.DescriptionCode language: VB.NET (vbnet)
The one exception is IsGenuine, which returns False rather than raising when no dongle is present — a license gate should fail closed, not blow up.
Do Not Gate on a Boolean
This is the part that decides whether the dongle is worth anything to you:
' Weak -- one patched jump defeats it.
If dongle.IsGenuine Then EnableFeature
' Strong -- the data your program needs only exists with the dongle present.
Dim coefficients() As Byte
coefficients = dongle.AppDecrypt(EncryptedBlobFromYourInstaller)Code language: VB.NET (vbnet)
Encrypt the constants, tables, thresholds or key material your application cannot compute, ship them encrypted, and decrypt them through the dongle at runtime. Scope them to keynubScopeDevice so only that one physical dongle can decrypt, or keynubScopeDeveloper so any dongle from your batch can.
twinBASIC
twinBASIC opens a VB6 .vbp directly and consumes the same COM server, so the code above is unchanged. Two differences: twinBASIC can build 64-bit, so register the 64-bit DLL for a 64-bit build; and twinBASIC implements CDecl properly, so you could call the flat C API directly. The SDK documents that route with its trade-offs — you lose the automatic close and Err.Description, and it no longer compiles in VB6.
The COM error numbers are stable, so your error handler keeps working across releases.
Sample project: samples/vb6/KeyNubDemo.vbp. See all supported languages or ask us a question.
Shipping the COM Server with a Visual Basic 6 Application
The binding is a COM server, KeyNub.dll, because VB6’s Declare statements emit stdcall calls and the SDK’s C API is cdecl; in a 32-bit process the two differ and the stack drifts on every call. Copy the DLL that matches your application’s bitness next to the executable or anywhere on PATH and register it once with the matching regsvr32: SysWOW64\regsvr32.exe for 32-bit hosts, System32\regsvr32.exe for 64-bit ones. It is self-contained, one file.
Registration does not need elevation: the server registers machine-wide when it can and falls back to the current user’s HKCU\Software\Classes when it cannot, so a per-user installer works. regsvr32 /u removes both. The COM server is Windows-only.
Questions Visual Basic 6 Developers Ask
Does the Dongle Work with a Visual Basic 6 Program in 2026?
Yes. VB6 executables are 32-bit, so they take the x86 build of the COM server, registered with the 32-bit regsvr32. The same object serves VBScript and HTA scripts.
Why Does VB6 Say Class Not Registered?
A bitness mismatch, nearly always: an in-process COM server can only be loaded by a host of its own architecture, and a 64-bit registration is invisible to a 32-bit process. Register the x86 build with SysWOW64\regsvr32.exe.
Does a Visual Basic 6 Application Need Administrator Rights to Talk to the Dongle?
No, and no driver either: the dongle is a USB HID device that the operating systems handle with their built-in class drivers. On Linux, install the shipped udev rule once so that ordinary users may open it; without the rule the SDK reports access denied and names the cause in its error detail.
Does a Visual Basic 6 License Check Need an Internet Connection?
No. Verification is a local exchange between your program and the dongle over USB: the SDK checks the dongle’s certificate chain to KeyNub’s root and runs a live challenge-response. There is no activation server and no account, so the check works on air-gapped machines.
Who Can Read the License Records on a Dongle?
Anyone holding the dongle: a program opens a session and reads records, and can decrypt data sealed for that dongle. Writing records, erasing them and incrementing counters need your write key. What the dongle guarantees is that none of it is available without the dongle present.
Can a License Written from Visual Basic 6 Be Read by a Program in Another Language?
Yes. Every binding drives the same core library and the same dongle, and records and sealed data are language-neutral bytes. Your issuing tool can be written in one language and your product in another.
Code
Runnable sample: vb6/KeyNubDemo.vbp. Binding source: bindings/com. Both are Apache-2.0, in the public SDK repository; the prebuilt native libraries are in the repository’s natives/ folder, one per platform.
All supported languages · All industries · Buy a KeyNub · Ask us something