This section outlines simple guidelines that you can follow to detect a real license, and if you don't find one, detect a trial license.
For example, say you have chosen a trial license as a way of providing your potential customer with demo versions of your software, but you might first want to check whether a real license is also available. (Note that there is no need to check or use a trial license if your end user has already bought a real one.) For this purpose, you can use the following code example to check out a license from a server, and when it is not available, to check out a trial license. If no licenses at all are available, the user will see the "Unable to checkout from trial license:" message, as shown below.
#include <stdio.h>
#include <stdlib.h>
#include "lmx.h"
LMX_HANDLE LmxHandle;
void exit_on_error(LMX_STATUS s)
{
if (s != LMX_SUCCESS)
{
if (LmxHandle != NULL)
{
fprintf(stderr, "%s\n", LMX_GetErrorMessage(LmxHandle));
LMX_Free(LmxHandle); // Release memory allocated by LM-X
}
else
{
fprintf(stderr, "%s\n", LMX_GetErrorMessageSimple(s));
}
fflush(stderr);
exit(1);
}
}
int main()
{
exit_on_error(LMX_Init(&LmxHandle));
if (LMX_Checkout(LmxHandle, "f2", 1, 0, 1) != LMX_SUCCESS)
{
printf("Unable to checkout from server license:\n");
printf("%s\n", LMX_GetErrorMessage(LmxHandle));
// If we cannot checkout a license from the server, we set the trial option and try to checkout a trial license
LMX_SetOption(LmxHandle, LMX_OPT_TRIAL_USES, (LMX_OPTION) 2);
if (LMX_Checkout(LmxHandle, "f2", 1, 0, 1) != LMX_SUCCESS)
{
printf("Unable to checkout from trial license:\n");
printf("%s\n", LMX_GetErrorMessage(LmxHandle));
LMX_Free(LmxHandle);
return 1;
}
}
LMX_Free(LmxHandle);
return 0;
}