This Code Sample is not a complete coding example, but serves to illustrate the key steps for implemeting the
StreamLined Activation method. For the complete code example, download the Code Samples from the DNA Control Panel.
Highlighted lines indicate where additional code is required or needs to be modified.
// definition of constants unShuffledMD5 and DNA_product_key
// 64-bit DLL MD5 - use the correct MD5 for the DNA Library used
//
#define unShuffledMD5 "5a304c147fca8fd97d41cfdd149b92c7"
// the DNA_Product_Key is emailed to you when you initially create a DNA Product
// You can have it resent to you from the DNA Control Panel
//
#define DNA_product_key ""
// at start-up of the application
//
// authenticate the DNA.DLL’s MD5
//
// declare variables used in MD5 check
char* MD5DigestHex;
MD5 md5 ;
MD5DigestHex = md5.digestFile( "DNA.DLL" );
if (strcmp((const char *)MD5DigestHex,unShuffledMD5)!=0)
{
// invalid MD5
// - quit the application
// - show error message (optional)
}
//
// load the dynamic DNA Library (applies to C, C++, Objective C)
//
errNo = LoadDNA("dna.dll");
//
// set the location of the CDM License File
// CDMPathName MUST be encoded in UTF-8
// This example shows the recommended location for a Windows OS Application
char* CDMPathName = "C:\\Users\\Public\\HelloWorld\\HelloWorld.CDM";
errNo = DNA_SetProperties("CDMPATHNAME",CDMPathName);
//
// call DNA_Validate() to see if a valid license exists
//
errNo = DNA_Validate(DNA_product_key);
if (errNo == 0 )
{
// valid CDM file, run the application
}
if (errNo < 0 )
{
// DNA_Validate has returned a Warning
// let the application run
// optionally, display a message to the User that a connection to
// the internet is required in the near future
// You can get the last date using DNA_PARAM()
// declaration of value buffer used with DNA_PARAM and DNA_ERROR
char buffer[255];
DNA_Param("VALIDATION_LIMIT",buffer,sizeof(buffer));
// display message to User
// let the application run
}
// The DNA_Validate() call has returned errNo > 0 - no valid license exists
//
// Implement the StreamLined Activation process using the DNA_Activate() API Call
// for activations and re-activations
//
// The DNA Server will itself determine if this is an initial activation
// or a re-activation of the License and will process accordingly
//
// get an Activation Code, Password(*) and Email from the User via a dialog box
// If you do not use the "User Authentication" option, then no need to capture a Password and assign
// a default password value
errNo = DNA_Activate(DNA_product_key, activation_code, password, license_email);
// check result code
// - errNo > 0 means failure
// - errNo = 0 and errNo < 0 means success
// see Developer Guides for the full list of return codes
// here we have only simple error checking in place
if (errNo <= 0 )
{
// success, run the application
}
else
{
// error occurred, quit the application
// optionally, you can display an error message
// you can use DNA_ERROR() which translate the errNo into a more
// user-friendly description, or use your own descriptions
DNA_Error(errNo,buffer,sizeof(buffer));
// display error explanation
// quit the application
}
//************** end of main code ***********************//
//************** De-Activation code **********************//
//
// For de-activation of the License to allow the User to install on another
// computer, the following code should be included
// in the response to a “De-Activate†button click or menu selection
//
// capture the License Password from the User using a dialog box
errNo = DNA_Deactivate(DNA_product_key, password);
if (errNo == 0)
{
// deactivation was OK, exit the application
}
else
{
// error occurred, quit the application
// optionally, you can display an error message
// you can use DNA_ERROR() which translate the errNo into a more
// user-friendly description, or use your own descriptions
DNA_Error(errNo,buffer,sizeof(buffer));
// display error explanation
// quit the application
}