Versions Compared

Key

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

...

The resulting file will be licenslicense.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.

...

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

MSCVMSVC:

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

...

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_STATUS LMX_Init(LMX_HANDLE *p)
Code Block
LMX_HANDLE LmxHandle;

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

LMX_STATUS LMX_SetOption(LMX_HANDLE LmxHandle,
                         LMX_SETTINGS eOption,
                         const void *pSetting);

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.

The In the following example presents using LMX_SetOption is used to set the license path to a license filethe current path.

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

...

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 type of function requires that the feature name, version and the count of the features be defined as shown below.

Code Block
LMX_STATUS LMX_Checkout(LMX_HANDLE LmxHandle, const char *szFeatureName, int nVerMajor, int nVerMinor, int nCount);

For example: 

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

...

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

Code Block
LMX_STATUS LMX_Checkin(LMX_HANDLE LmxHandle, const char *szFeatureName, int nCount"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
void LMX_Free(LMX_HANDLE hLmxHandle);

The following example illustrates a basic example of an LM-X licensed application.

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
  run_my_features();
 
  LMX_Checkin(LmxHandle, "feature", LMX_ALL_LICENSES);
  LMX_Free(LmxHandle);
  return 0;
}

"You should save this If you decide to copy and paste the above code block, save it as an example.c." What do you mean by that?

Running the application is straightforward and involves the following steps:

To run an LM-X licensed application:

...

.

Compilation

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

...

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 localexample localexample.o /usr/lmx-sdk-4.6.1/linux_x64/liblmxclient.a -pthread -lrt -ldl

...

Now you should have the following files in your current directory:

FileDescription
license.xml

...

Your license template.
license.licReady to use license, generated with xmllicgen.
example.c

...

Your first program source code.
example/example.exe

...

Your program executable.

Now run your first LM-X licensed application.