After you've created a new product, go to the version page of the product you will be adding licensing to. You will need to do 2 things:
You'll be including the TurboActivate.dat file in the same folder as the TurboFloat.dll file and you'll use the Version GUID in your code as part of integrating TurboFloat within your app.
The first thing you need to do is fix a setting in the Visual Basic 6 IDE. Click the "Tools -> Options..." menu. Then click the "General" tab and set the "Error Trapping" to "Break on Unhandled Errors". Then press OK.
Included in TurboFloat Library package is a simple VB6 example project. You can find it in the "API\VB6" folder after you've downloaded and extracted the TurboFloat Library package. We recommend playing around with the example app first, before you start integrating TurboFloat into your application.
The following files are what you'll be including in your app:
Visual Basic 6 is a special kind of beast. Instead of using the regular "cdecl" TurboFloat.dlls available in either the "x86" or "x64" folders inside the "Main TurboFloat package", you'll have to use the TurboFloat.dll from inside the "stdcall\x86" folder.
Visual Basic 6 is an ancient language that will seemingly never die. So, until VB6 dies (and you switch to the infinitely better VB.NET), you'll have to make note of, and workaround, the following bugs in Visual Basic 6:
You must always open your VB6 project file by double clicking your *.vbp file. You cannot open the project by clicking "File -> Open Project..." or by clicking the filename in the recent projects list in the "File". The reason you absolutely cannot do those things is that VB6 won't be able to load our native "TurboFloat.dll" if you do anything other than open your project by double clicking your project file.
Unfortunately the entire VB6 IDE crashes if you don't exit your app normally (by closing your app like you would any other program). If you click the "End" button to stop the debugging then the VB6 IDE crashes.
VB6 doesn't support "unsigned short" values, meaning you can only use Ports between 0 and 32,767 (anything about 32,767 will cause an overflow).
Because VBA & VB6 don't support threading there's one feature that won't be available in this language that is available in modern languages. When the "tf_LeaseChange" is called by TurboFloat the "TF_CB_FEATURES_CHANGED" will never be returned for the status. Even if there are new custom license fields delivered by the TurboFloat Server, you'll never be notified that they came in.
We're going to walk you through adding floating licensing to your app by using our VB6 example application. If you haven't downloaded it already you can get the example app inside the TurboFloat Library package.
In the example "Text Editor" VB6 application the "frmMain.frm" file is the main UI for the app. That is, it's the entry point for the application. And because it's the entry point of the application it's where we'll be requesting the "license lease" from the TurboFloat Server.
First, create the TurboFloat instance in your main form:
' define the TurboFloat instance ("tf") and ' tell it to handle events Public WithEvents tf As TurboFloat
Then, in the Form_Load event handler for the form, you'll actually create the new instance of the TurboFloat class. Paste the Version GUID you copied from earlier:
Private Sub Form_Load() ' create the new TurboFloat instance Set tf = New TurboFloat ' tell your app to handle errors in the section ' at the end of the sub On Error GoTo TFProcError 'TODO: goto the version page at LimeLM and paste this GUID here Call tf.Init(Me, "PASTE-VERSION-GUID-HERE") ProcExit: Exit Sub TFProcError: ' err handling code here End Sub
Next, we'll actually request the lease from the TurboFloat Server:
'TODO: goto the version page at LimeLM and paste this GUID here Call tf.Init(Me, "PASTE-VERSION-GUID-HERE") ' request the lease Call tf.RequestLease
The native TurboFloat library handles all the details about renewing leases, retrying, etc. All you have to do is handle the cases where TurboFloat talks to your app and tells it something has changed (license lease failing to be renewed or new license field data). To do this you need to handle the LeaseChange event:
Private Sub tf_LeaseChange(ByVal status As TF_LeaseStatus) If status = TF_CB_FEATURES_CHANGED Then 'TODO: if you're using feature values in your app ' you might want to reload them now. Else ' TF_CB_EXPIRED, TF_CB_EXPIRED_INET, and everything else ' Immediately disable the app and/or show a modal ' form that gives the user the option to Save / ' Save As the data (if applicable) and let the ' user re-try connecting to the server. Me.Enabled = False 'Note: Don't just close your app. Your users will be ' rightfully ticked-off if you do something like that. ' Instead, we're showing a modal dialog that lets the ' user try to get a new lease from the server. Or, ' if they can't, then save their data. Dim frmLeaseExp As LeaseExpired Set frmLeaseExp = New LeaseExpired If frmLeaseExp.ShowDialog(tf) = vbCancel Then ' close the app immediately Unload Me Exit Sub End If ' We've gotten a new lease, so re-enable the app. Me.Enabled = True End If End Sub
Included in the example VB6 app are 3 forms that you might want to copy to your own application:
LeaseExpired.frm: a form to show if the license lease has expired.
frmInternetErr.frm: a form to show if there's an internet error (that is, a server is specified, but your app couldn't connect to the server).
ServerConfig.frm: a form to allow the end-user to enter details about where their TurboFloat Server is located.
You've already seen example usage of the LeaseExpired form in the LeaseChange event handler. Here's an example usage of the ServerConfig and frmInternetErr forms. Its logic is fairly simple. First it tries to get a lease, and if that fails then it prompts the user for action:
Private Sub Form_Load() ' create the new TurboFloat instance Set tf = New TurboFloat ' tell your app to handle errors in the section ' at the end of the sub On Error GoTo TFProcError 'TODO: goto the version page at LimeLM and paste this GUID here Call tf.Init(Me, "18324776654b3946fc44a5f3.49025204") ' request the lease Call tf.RequestLease AfterRequest: ' If you've reached this point then your app has ' successfully acquired a license lease. If you ' have custom license field values that you want ' to use, you can get them now. ' See: http://wyday.com/limelm/help/license-features/ 'Dim fieldValue As String 'fieldValue = tf.GetFeatureValue("your field name", "default value") 'TODO: do something with the fieldValue ProcExit: Exit Sub TFProcError: If Err.Number = TF_E_INET Or _ Err.Number = TF_E_INET_TIMEOUT Or _ Err.Number = TF_E_WRONG_SERVER_PRODUCT Or _ Err.Number = TF_E_USERNAME_NOT_ALLOWED Then ' Give the user an option to try another server if they ' couldn't connect to the first one, or if the first one ' is for a different product. Dim inetErr As frmInternetErr Set inetErr = New frmInternetErr If inetErr.ShowDialog(tf) = vbOK Then Resume AfterRequest Else ' close the app immediately Unload Me Exit Sub End If ElseIf Err.Number = TF_E_SERVER Then ' if it's a server error, then prompt for the server Dim srvConf As ServerConfig Set srvConf = New ServerConfig If srvConf.ShowDialog(tf) = vbOK Then Resume AfterRequest Else ' close the app immediately Unload Me Exit Sub End If End If MsgBox "Failed to get a lease from the floating license server: " & Err.Description ' End your application immediately Unload Me End Sub
After you've successfully requested a lease from the TurboFloat Server, the TurboFloat library integrated in your app takes care of renewing the leases automatically and silently. You'll only ever get a notification of something going wrong in the handler for the LeaseChange event that we covered in Step 3.
When your app is closing you should "drop" the lease using the
DropLease() method, and cleanup the memory using the
Private Sub Form_Unload(Cancel As Integer) ' since we're closing we can just skip the errors if the dropped ' lease fails the lease will become a zombie. On Error Resume Next ' drop the lease If tf.HasLease Then Call tf.DropLease End If ' cleanup memory, etc. ' Note: if you're going to wait for a successful "DropLease" call ' (instead of the current behavior of trying to drop the ' lease and exiting whether the lease was dropped or not) ' then you must not call tf.Cleanup until you finished ' calling any other TurboFloat function. I.e. only call ' tf.Cleanup as the last TurboFloat function. Call tf.Cleanup End Sub
What this does is tell the TurboFloat Server that you're through using the lease in this instance of your app, and another instance of your app on another computer or another session can now use that "free slot".
If you can't drop the lease (because your app can't connect to the internet, or for any other reason), and you choose to exit your app anyway, then the "lease" on the TurboFloat Server will be a "zombie". The lease will expire eventually on the TurboFloat Server, and thus the free slot will open back up.
Testing requesting leases, dropping them, and everything else in the TurboFloat Library is intuitive: just call the function and it does the thing you want it to do. Testing the lease change event is, however, slightly less intuitive. Here's how you can test the lease change event:
If your app is open and has a lease, close your app and make sure it drops the license lease from the TurboFloat Server.
Stop the TurboFloat Server instance.
Save the changes you made to the configuration file.
Start your TurboFloat Server instance again.
Start your app again, and make sure it successfully gets a license lease from the TurboFloat Server.
Now, stop the TurboFloat Server instance, but leave your app running.
Within the next 30 seconds the lease change event will be called because the TurboFloat Library was not able to renew the license lease automatically.