SDKs
...
Getting Started
C++

C-Interface

9min

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. 

SDK Configuration

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.

C


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.

C


License Activation

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.

C


Local License

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

C


License Check

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.

C


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.

Full Code Sample

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.

C


License Deactivation

Deactivating a license unbinds the device from the license, and decrements the number of total activations. Deactivating is done using the following method:

C


Common Errors

The license checks can produce the following errors:

Error

Definition

eLicenseDisabled

eLicenseInactive

eLicenseExpired

License is in invalid state (disabled, epired or inactive)

eProductMismatchError

License does not belong to configured product

eDeviceError

License does not belong to current device

eDeviceBlacklisted

The device has been blacklisted

eClockTamperedError

Detected cheating with system clock

eNoInternetError

eNetworkTimeoutError

eSreverError

Connection-related errors: if there's no Internet or an internal server error occured