website logo
⌘K
Getting Started
Introduction
Basic Concepts
Opening an Account
Creating & Configuring Products
Integrating SDK and Configuring License Fulfillment
Activate a Key-Based License
Vendor Platform
Issuing New Licenses
License Detail View
Order Detail View
Customer Detail View
Metadata
Analytics
Settings
Product Configuration
Product Features
Product Custom Fields
Product Versioning
License Policies
Product Bundles
License Entitlements
License Types
Activations & Device Transfers
Features
Custom Fields
License Start Date
License Note
Maintenance Period
Trial Licenses
Floating Licenses
License Activation Types
Portals
End-User Portal
Offline Portal
Air-Gapped Portal
License API
License API Authorization
License Activation/Deactivation
License Check
Consumption
Floating
Trial Key
Product Details
Device Variables
Changing Password
Management API
Making API Requests
Management API Authorization
Customer
Product
Order
License
Device
Analytics
SDKs
Tutorials
.NET/C# SDK
.NET/C# Management SDK
C++ SDK
Java SDK
Python SDK
Go SDK
Delphi SDK
Swift/Objective-C SDK
Android SDK
Unity SDK
Errors and Response Codes
Floating Server
API Reference
Deployment
Configuration
Floating Server UI
Securing the Server
Whitelabeling
FAQ
Floating Server Changelog
Integrations
Salesforce
FastSpring
Stripe
Shopify
Common Scenarios
Single Sign On (SSO)
Glossary
General
SDK Glossary
Vendor Platform
Product Configuration Glossary
License Configuration
Postman Collections
Frequently Asked Questions
Changelog
License API changelog
Platform changelog
Docs powered by
Archbee
SDKs
...
Getting Started
C++

C++ SDK Configuration and Usage

15min

C++ SDK allows implementing licensing in two ways: - using the License and LicenseManager classes; - using the LicenseHandler class.

LicenseHandler encapsulates License and LicenseManager functionality. By default, it is exceptions-free, but you can enable exceptions. It's up to you whether to use LicenseManager and License directly or use this class. LicenseHandler is also useful for Unreal Engine clients because it is free of memory access violation problems due to runtime conflicts with UE.

This article has code samples for both approaches. In the other ones, we will demonstrate SDK usage only with LicenseManager and License. LicenseHandler class has methods corresponding to License/LicenseManager functionality.

See also our Error Handling tutorial.

Configuration

To initialize the SDK you will need to fill in your application name and version, LicenseSpring API key, shared key and product code.

Both the API key and shared key can be found on your LicenseSpring account under Settings->Keys:

API and Shared Key Location
API and Shared Key Location


Your product code is located in your product list under Configure Products:

Product CoProduct Code Location Location
Product Code Location


Please, keep in mind that the product code field is case-sensitive.

When you have the necessary values, create the configuration.

C++
|
std::string AppName = "My LicenseSpring Application";
std::string AppVersion = "1.0.0";
std::string ApiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
std::string SharedKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
std::string ProductCode = "XX";

auto configuration = LicenseSpring::Configuration::Create( ApiKey, SharedKey, ProductCode, AppName, AppVersion );


Now you can initialize LicenseManager or LicenseHandler using this configuration object.

LicenseManager
LicenseHandler
|
auto licenseManager = LicenseManager::create( configuration );


License Activation

The license keys are located in Licenses section:

License Key Location
License Key Location


To implement user-based licensing please refer to: User-Based Licensing.

To activate a license, create a LicenseID using the given key and call activation method.

LicenseManager
LicenseHandler
|
 auto licenseId = LicenseID::fromKey( "XXXX-XXXX-XXXX-XXXX" );
 auto license = licenseManager->activateLicense( licenseId );


The process of activating a license refers to binding a device to a license. On the LicenseSpring platform, activating the license increments the total activations counter within the license.

Local License

The local license is a copy of the license information that is saved on the end user's local computer. Users who have not activated the license on their end before will not have a local license. By default, the local license is stored: %USERPROFILE%\AppData\Local\LicenseSpring\”Product Code”\License.key.

See Local License File for more information.

If a device already has a license, and you try to activate another license on that device, for the same product, that newly activated license will override the existing license, deleting it from the device. This will be on the developer to make sure that they check if a license exists on the device before a new activation:

LicenseManager
LicenseHandler
|
auto license = licenseManager->getCurrentLicense();
if( license == nullptr )
    //activate a new license


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 and has not been transferred.

It is also useful to check whether the local license file has been tampered with and whether the local license is still valid.

License
LicenseHandler
|
license->localCheck();
//throws exceptions in case of errors


The local check can produce the following errors:

Exception

Error code

Reason

LicenseStateException

eLicenseDisabled

eLicenseInactive

eLicenseExpired

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

ProductMismatchException

eProductMismatchError

License does not belong to configured product

DeviceNotLicensedException

eDeviceError

License does not belong to current device

ClockTamperedException

eClockTamperedError

Detected cheating with system clock

Online license check refreshes the local license with the data from LicenseSpring backend:

License
LicenseHandler
|
license->check();
//throws exceptions in case of errors


The online check can produce the following errors:

Exception

Error code

Reason

LicenseStateException

eLicenseDisabled

eLicenseInactive

eLicenseExpired

License is disabled, was reset or expired

DeviceNotLicensedException

DeviceBlacklistedException

eDeviceError

eDeviceBlacklisted

License does not belong to current device or the device was blacklisted

NoInternetException

NetworkTimeoutException

LicenseServerException

eNoInternetError

eNetworkTimeoutError

eServerError

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

This method also returns the most recent InstallationFile available for the license which can be useful for managing software updates.

For more information about managing software updates, see Handling Product Versions.

You can also check for active, valid, enabled, and expired licenses using isActive, isValid, isEnabled, and isExpired methods respectively.

Note that an active license does not necessarily mean a license is valid. A valid license means the license is active, enabled, and not expired. An active license means that the license is bound to a device, but may also be disabled or expired.

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.

LicenseManager
LicenseHandler
|
std::string AppName = "My LicenseSpring Application";
std::string AppVersion = "1.0.0";
std::string ApiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
std::string SharedKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
std::string ProductCode = "XX";

auto configuration = LicenseSpring::Configuration::Create( ApiKey, SharedKey, ProductCode, AppName, AppVersion );
try
{
    auto licenseManager = LicenseManager::create( configuration );
    auto license = licenseManager->getCurrentLicense();
    if( license == nullptr )
    {
        auto licenseId = LicenseID::fromKey( "XXXX-XXXX-XXXX-XXXX" );
        license = licenseManager->activateLicense( licenseId );
    }
    license->localCheck();
    license->check();
}
catch( const LicenseSpringException& ex )
{
    std::cout << "LicenseSpring exception encountered: " << ex.what();
}


License Deactivation

Deactivating a license unbinds the device from the license, and decrements the number of total activations. Depending on the license transfer policy, this usually means that the license is freed up to be activated onto a new device. Deactivating is done using the following method:

License
LicenseHandler
|
if( license->deactivate() )
    std::cout << "License deactivated successfully.";


The License::deactivate() method allows to specify whether you want to remove the local license file after the deactivation. Set the removeLocalData parameter to true if you want the local files to be removed.

Updated 15 Sep 2023
Did this page help you?
PREVIOUS
C++ SDK Installation
NEXT
C-Interface
Docs powered by
Archbee
TABLE OF CONTENTS
Configuration
License Activation
Local License
License Check
Full Code Sample
License Deactivation
Docs powered by
Archbee