Defining the Custom Locking Criteria

Declare Variables/Constants

Define the implementation of the callback function:

static long callback_impl_custom_ex(String pcInput, IntPtr pcOutput, ref uint piSizeOutput)
        {
            if (pcOutput == IntPtr.Zero)
            {
                // The licensing library is asking for the size of memory buffer to be allocated.
                if (piSizeOutput == 0)
                {
                    piSizeOutput = (uint)SAMPLE_CALLBACK_OUTPUT_XML.Length; //Output XML described below
                }
                else
               {
                    return 1;            //return error
                }
            }
            else
            {
       // Non-NULL means licensing library has allocated the required buffer space and asking for the actual  
              data to be copied into this buffer.
                 try
                {
                    byte[] chars = System.Text.Encoding.ASCII.GetBytes(SAMPLE_CALLBACK_OUTPUT_XML + '\0');
                    Marshal.Copy(chars, 0, pcOutput, chars.Length);
                }
                catch (Exception e)
                {

                }

            }
            return (0);             // return 0 to indicate success
        }

Where SAMPLE_CALLBACK_OUTPUT_XML is defined as:
 public static String SAMPLE_CALLBACK_OUTPUT_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
"<callbackOutputData>"+ 
      "<customFingerprint>"+
                    "<item>" +
                       "<rawValue>111222333444555666777888999aaab</rawValue>"+
                     "</item>"+
                     "<item>"+
                        "<rawValue>abcdef0123456789abcdef012345678</rawValue>"+
                     "</item>"+
      "</customFingerprint>"+
"</callbackOutputData>";

API Calls

To register the custom locking callback in your application, execute the APIs in the specified sequential order only:

>ApplicationContext.ICallback customexCallback = new ApplicationContext.ICallback(callback_impl_custom_ex);

>ApplicationContext.registerCallback(null, LicensingConstants.SNTL_CALLBACK_TYPE_CUSTOM_FINGERPRINT, customexCallback);

If the ApplicationContext.registerCallback call is successful, the registered callback will be invoked by the licensing library whenever locking-related information is sought/retrieved/verified by the licensing library.

Notes

>ApplicationContext.registerCallback API has global scope and its effect is valid for all app-contexts once set. This API should be called before creating any app-context. If this api is called after performing any licensing-related operations then complete licensing library is re-initialized which means all prior created app-contexts become invalid and also all earlier licenses are reloaded if library is in standalone mode.

> Registered callback is invoked twice by the licensing library for every atomic operation. First invocation is to ask the callback about the buffer size in bytes that is needed to hold the response output buffer. In the second invocation it expects the callback to write the output contents into the allocated buffer passed as the second arguments.

>For illustration purpose, we have taken static contents for variable SAMPLE_CALLBACK_OUTPUT_XML. In real world applications, this output could be built dynamically depending upon vendor’s requirements.