Sam,
I included the whole main.c below. The only thing different is the GUID, in the code below, I used the one from the example.
I do a qDebug() on the tfHandle and it returned "0".
hr = TF_RequestLease(tfHandle); returns "9".
#include "mainwindow.h"#include <QApplication>
#include <stdio.h>
/* Support Unicode compilation and non-Windows compilation */#ifdef _WIN32 #include <Windows.h> #include <tchar.h>#else #define _T(x) x typedef char TCHAR;#endif
#include "TurboFloat.h"
uint32_t tfHandle;
// here we're just printing a license field.// of course, in your app you'll want to do something// useful with license fields.void PrintLicenseField(){ TCHAR * featureValue;
//TODO: change this feature name to any licens field name // that you want to print out.
// TCHAR * featureName = (TCHAR *) _T("expiry"); wchar_t * featureName = L"expiry";
// if this app is activated then you can get a feature value (completely optional) // See: http://wyday.com/limelm/help/license-features/
HRESULT hr = TF_GetFeatureValue(tfHandle, featureName, 0, 0);
featureValue = (TCHAR *)malloc(hr * sizeof(TCHAR));
hr = TF_GetFeatureValue(tfHandle, featureName, featureValue, hr);
if (hr == TF_OK) {#ifdef _WIN32 wprintf(L"Feature value: %s\n", featureValue);#else printf("Feature value: %s\n", featureValue);#endif } else printf("Getting feature failed: %d\n", hr);
free(featureValue);}
/* This function will be called by TurboFloat from a separate thread. That means if you're displaying UI to your users you must ensure that any windows (or any resource sharing for that matter) are created in the right thread context or bad things might happen.
Test this behavior well before releasing to your end-users. You can do that by starting the TurboFloatServer with a short lease time. Then, on your test computer where this app is running, unplug or disable your internet connection to ensure your app can't contact the server (and thus TF_CB_EXPIRED_INET will be passed to this function).*/void TF_CC LeaseCallback(uint32_t status){ switch (status) { case TF_CB_FEATURES_CHANGED: //TODO: reload any features using TF_GetFeatureValue(). printf("TODO: reload any features using TF_GetFeatureValue()\n"); PrintLicenseField();
break;
// explicitly handle errors // also, handle unknown statuses ("default") // as errors. case TF_CB_EXPIRED: case TF_CB_EXPIRED_INET: default:
//TODO: disallow any features in your app. printf("The lease expired before it could be renewed.\n");
/* After disabling the user's access to your app, we recommend you do 3 things:
1. Give the user the option to save their progress.
2. Give the user the option to save their progress to a separate file (i.e. "Save as" in case the work they were doing was incomplete).
3. Give the user the option to retry. For example a "Try again" button that calls TF_RequestLease(tfHandle).
*/
// Don't just exit the app without warning or without giving the user options. // For example, this behavior right here is a terrible example to be setting: printf("The app is exiting. In your app you shouldn't just abruptly exit! That's bad. See the comments in the example app.\n"); exit(1); break; }}
int main(int argc, char *argv[]){
//Turbo float code
/* Used to store TurboFloat responses. */ HRESULT hr;
/* Get the handle that will be used for TurboFloat function calls.
TODO: paste your Version GUID here. */ //tfHandle = TF_GetHandle((STRCTYPE) _T("18324776654b3946fc44a5f3.49025204")); tfHandle = TF_GetHandle(L"18324776654b3946fc44a5f3.49025204");
qDebug() << tfHandle;
/* Set the function that TurboFloat will call from another thread letting your app know about changes to the floating license. */ hr = TF_SetLeaseCallback(tfHandle, LeaseCallback);
hr = TF_RequestLease(tfHandle);
qDebug() << hr;
if (hr == TF_E_SERVER) { /* We're just harcoding the localhost for testing purposes in real life you'd want to let the user enter the host address / port you can either do this in your app, or in your installer. */
//hr = TF_SaveServer(tfHandle, (STRTYPE) _T("127.0.0.1"), 13, TF_SYSTEM); hr = TF_SaveServer(tfHandle, L"127.0.0.1", 13, TF_SYSTEM);
if (hr != TF_OK) { printf("Failed to save the sever details (TF_SaveServer() returned %d). Look in TurboFloat.h for a human readable explanation of the error.\n", hr); return 1; }
/* try to get a lease again */ hr = TF_RequestLease(tfHandle); } else if (hr == TF_E_INET || hr == TF_E_WRONG_SERVER_PRODUCT) { /* 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. */ }
// If the lease wasn't acquired then output an error and exit. // You can view all the error codes in TurboFloat.h near the bottom of the file. if (hr != TF_OK) { printf("Failed to get the floating license lease (TF_RequestLease() returned %d). Look in TurboFloat.h for a human readable explanation of the error.\n", hr); return 1; }
/* The floating license lease requested successfully.
Here's where you let your user start using your app. */ printf("Floating license lease was requested successfully.\n\n"); printf("Type \"X\" and press Enter to \"drop\" the lease (make it available for other instances of your app) and then exit the app.\n\n");
/* Here we'll just read in any license fields and print them out.
Of course in your actual app you'll handle the license fields however you need to (for instance, to limit functionality of your app). */ PrintLicenseField();
/* Loop until the user typed "X" to Release the lease and exit the app. */ while (getchar() != 'X') { }
/* Drop the floating license, wait for the response, then exit your app. */ hr = TF_DropLease(tfHandle);
/* Output the error if there is one. Look in TurboFloat.h for what the error codes mean. */ if (hr != TF_OK) printf("Dropping the lease failed: (%d), exiting anyway. Look in TurboFloat.h for a human readable explanation of the error.\n", hr);
/* Cleanup the memory. */ hr = TF_Cleanup();
QApplication a(argc, argv); MainWindow w; w.showMaximized(); w.show(); w.setWindowTitle("Lucidus Validation Suite");
return a.exec();}