Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Now that you have defined a license templatepolicy, you can need a license template to integrate LM-X with your application. First, try the following examples, which are already integrated

License file

To generate an XML license template:

  1. Create a template of the license you are interested in.
  2. Run the license generator provided with LM-X

...

To use the LM-X API in your code and make the code compile, you must:

  • Include the lmx.h header file.
  • Add the include path for LM-X to the include directories.
  • Link with the liblmxclient library.

To perform these steps, do the following: 

For Windows, in Visual Studio: 

  1. Include this code into your application to import the LM-X functions:
    #include "lmx.h"
  2. Under Configuration Properties, select C/C++.
  3. Add the LM-X path, LM-X_dir\include, to the Additional Include Directories.
  4. Under Additional Dependencies, add the LM-X library path, for example:
    LM-X_dir\win32_x86\liblmxclient_mt.lib 

For Unix, at a command line:

  1. Include this code into your application to import the LM-X functions:
    #include "lmx.h"
  2. With the GCC compiler, specify an LM-X include directory:
    gcc -c –I LM-X_dir/include source_file
  3. When linking, specify the LM-X library paths, for example:
    gcc -o application objects LM-X_dir/lib/liblmxclient.a
  1. , xmllicgen, as described in Generating licenses.

In the following example we assume the license will expire on January 1, 2018. This license defines one feature with version 1.0.

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<LICENSEFILE>
  <FEATURE NAME="feature">
    <SETTING MAJOR_VERSION="1"/>
    <SETTING MINOR_VERSION="0"/>
    <SETTING END="2018-01-01"/>
  </FEATURE>
</LICENSEFILE>

Run xmlicgen to convert the above LM-X license template to a license file.

On Unix:

Panel

 # xmllicgen license.xml 

On Windows:

Panel

# xmllicgen.exe license.xml

The resulting file will be license.lic. Xmllicgen will automatically replace your ".xml" extension with ".lic" and save the license next to your template.

Source code

Header file

First of all, you must include the required header, lmx.h, located in the include directory of your SDK.

Code Block
#include "lmx.h"

If your project and LM-X SDK are in separate directories, remember to specify the include directory for your compiler. For example:

GCC:

Panel
gcc -I /usr/lmx-sdk-4.6.1/include/

MSVC:

Panel
cl.exe /I “C:\Program Files\X-Formation\LM-X SDK v4.6.1 win64_x64\include\”

Commonly used functions

In the following examples we will present five commonly used LM-X API functions.

LMX_Init

The LMX_Init function initializes the protection system. This function creates a handle needed to use other LM- X API functions. It returns LMX_STATUS variable that indicates initialization status.

Code Block
LMX_HANDLE LmxHandle;

if (LMX_Init(&LmxHandle) != LMX_SUCCESS)
{
  printf("Unable to initialize!\n");
  return 1;
}

LMX_SetOption

The LMX_SetOption function sets up flags that change licensing behavior prior to license checkout. This function returns LMX_STATUS variable that indicates the status of initialization.

In the following example LMX_SetOption is used to set the license path to the current path.

Code Block
LMX_SetOption(LmxHandle, LMX_OPT_LICENSE_PATH, ".");

LMX_Checkout

The LMX_Checkout function is one of the most important LMX API functions, because it checks out one or more licenses for a specific feature. This function requires that the feature name, version and the count of the features be defined as shown below.

Code Block
if (LMX_Checkout(LmxHandle, "feature", 1, 0, 1) != LMX_SUCCESS)
{
  printf("Unable to checkout\n");
  LMX_Free(LmxHandle);
  return 1;
}

LMX_Checkin

The LMX_Checkin function returns the licenses for a single checked out feature or all checked out features.

Code Block
LMX_Checkin(LmxHandle, "feature", LMX_ALL_LICENSES);

LMX_Free

The LMX_Free function, which has an inverse effect to LMX_Init, frees any allocated memory used by the licensing system and closes any open connection to a license server.

Code Block
LMX_Free(LmxHandle);

Making it work

The following example illustrates a complete, compiled example that includes source code necessary to license your application using LM-X License Manager.

Code Block
#include <stdio.h>
 
#include "lmx.h"
 
int main()
{
  LMX_HANDLE LmxHandle;
 
  if (LMX_Init(&LmxHandle) != LMX_SUCCESS)
  {
    printf("Unable to initialize!\n");
    return 1;
  }
 
  // Look for licenses in current directory.
  LMX_SetOption(LmxHandle, LMX_OPT_LICENSE_PATH, ".");
  if (LMX_Checkout(LmxHandle, "feature", 1, 0, 1) != LMX_SUCCESS)
  {
    printf("Unable to checkout!\n");
    LMX_Free(LmxHandle);
    return 1;
  }
  // Here you are safe to run your licensed features
  printf("Here you can run your features\n");
 
  LMX_Checkin(LmxHandle, "feature", LMX_ALL_LICENSES);
  LMX_Free(LmxHandle);
  return 0;
}

If you decide to copy and paste the above code block, save it as an example.c.

Compilation

Let's assume you saved your program source code as an example.c and installed your LM-X SDK in the default directory.

To compile your first program run the following:

GCC:

Code Block
gcc -c -pthread -fPIC -Wall -Werror -fno-strict-aliasing -m64 -Wfatal-errors -Wno-unused-local-typedefs -Wno-vla -Wno-attributes -O2 -c -O2 -I/usr/lmx-sdk-4.6.1/include/ example.c 

gcc -static-libgcc -o example example.o /usr/lmx-sdk-4.6.1/linux_x64/liblmxclient.a -pthread -lrt -ldl

MSVC:

Code Block
cl /WX /MT /c /O2 -D_CRT_SECURE_NO_DEPRECATE /I "C:\Program Files\X-Formation\LM-X SDK v4.6.1 win64_x64\include\" example.c
 
link /WX /opt:noref example.obj "C:\Program Files\X-Formation\LM-X SDK v4.6.1 win64_x64\win64_x64\liblmxclient_mt.lib"

Running your application

Your current directory should include the files listed in the table below.

FileDescription
license.xmlYour license template.
license.licReady to use license, generated with xmllicgen.
example.cYour first program source code.
example/example.exeYour program executable.

Now run your first LM-X licensed applicationWith your development environment ready to use the LM-X API, you will be able to implement license checking in your application code.