The C interface of LicenseSpring's C++ SDK allows using SDK features in C applications. This tutorial will explain how to implement licensing in a C application using the LicenseSpring SDK.
In this article we will look at activating, checking, and deactivating licenses. This functionality can be implemented using the LSLicenseHandler struct. It is a wrapper of C++ LicenseHandler class and is similar in use.
To initialize the SDK you will need to fill in your application name and version, LicenseSpring API key, shared key and product code. For more information about getting these values see: Getting API key and shared key
When you have the necessary values, create the LSConfiguration object.
You have to create a LSExtendedOptions object even if you don’t intend to change its values. It is necessary to copy the default values to the LSConfiguration. Then you can delete the options object.
Now you can create and initialize LSLicenseHandler using this configuration.
To activate a license, you need its key or user email and password. For information about getting license keys see: Key-based license activation
For information about user based licenses see: Adding user to a license
Using these values, create a LSLicenseID and call activation method.
Make sure that you check if a license exists on the device before a new activation. For more information see: C++ SDK Configuration and Usage
It is recommended to perform a local license check at application start to confirm that the local license file belongs to the current device, has not been tampered with and is still valid.
Online license check refreshes the local license with the data from LicenseSpring backend.
This method also returns the most recent LSInstallationFile available for the license which can be useful for managing software updates. [TODO: insert link to the article about handling versions]
You can also check for active, valid, enabled, and expired licenses using isLicenseActive, isLicenseValid, isLicenseEnabled, and isLicenseExpired methods respectively.
Below you can find a code sample that initializes the SDK, retrieves a local license or activates a new one, and performs the necessary checks.
Deactivating a license unbinds the device from the license, and decrements the number of total activations. Deactivating is done using the following method:
The license checks can produce the following errors:
License is in invalid state (disabled, epired or inactive)
License does not belong to configured product
License does not belong to current device
The device has been blacklisted
Detected cheating with system clock
Connection-related errors: if there's no Internet or an internal server error occured