This Code Sample is not a complete coding example, but serves to illustrate the key steps for implemeting the
Custom 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 Custom Activation Re-Activation process
//
// Implement the 2-step Activation / Re-activation process
//
// Step 1 : get License code and call DNA_Query() to determine license status
// Step 2 : get additional info and call DNA_Activate or DNA_Reactivate()
// based on status
//
// Step 1
// get an Activation Code from the User via a dialog box
// use DNA_Query() to determine if activate or re-activate
errNo = DNA_Query(DNA_product_key,activation_code);
// DNA_Query returns:
// - ERR_ACTIVATION_EXPECTED(8) = Single-User License with Roll-Over needs to be activated
// for the 1st time
// - ERR_REACTIVATION_EXPECTED(9) = Single-User License with Roll-Over already activated,
// needs to be re-activated
// - ERR_ACTIVATION_EXPECTED_MU(19) = Single-User License without Roll-Over, Multi-User or Floating License needs to
// be activated for the 1st time
// - ERR_REACTIVATION_EXPECTED_MU(20) = Single-User License without Roll-Over, Multi-User or Floating License already activated,
// this is a new seat activation, use DNA_Reactivate()
// if the code does not exist, DNA_Query() will return 8 as though an activation
//
// Step 2 : based on DNA_Query() result, complete the process
//
if ((errNo == ERR_ACTIVATION_EXPECTED) || (errNo == ERR_ACTIVATION_EXPECTED_MU))
{
// this is an activation, get a password and email address
// if your product does not use User Authentication (i.e. a License
// password), then use a hard-coded non-blank string as a "global"
// Password
// get password and email address from User via dialog box
// you may want to validate the inputs, at a minimum:
// - not >blank<
// - password length not > 16 characters, no spaces
// - valid email format
errNo = DNA_Activate(DNA_product_key, activation_code, license_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
}
}
if (errNo == ERR_REACTIVATION_EXPECTED)
{
// this is a reactivation for Single-User with Roll-Over Re-Activation
// and User Authentication that requires a current password
// and NEW password
// get current and New password from User via dialog box
// you would also want to validate the inputs, at a minimum:
// - not <blank>
// - password length not > 16 characters, no spaces
// issue the DNA_Reactivate API call and report the result
errNo = DNA_Reactivate(DNA_product_key, activation_code ,license_password, license_new_password);
// check result code
// - errNo > 0 means failure
// - errNo = 0 and errNo < 0 means success
// 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
}
}
if (errNo == ERR_REACTIVATION_EXPECTED_MU)
{
// this is a reactivation for the following license types:
// - Multi-User, Floating
// - Single-User without Roll-Over Reactivation
// - Single-User without User Authentication
// if your product does not use User Authentication (i.e. a License
// password), then use a hard-coded non-blank string as a "global"
// Password
// get License password from User via a dialog box
// issue the DNA_Reactivate API call
// use <blank> for new password and report the result
errNo = DNA_Reactivate(DNA_product_key, activation_code, license_password,"");
// check result code
// - errNo > 0 means failure
// - errNo = 0 and errNo < 0 means success
// 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
}
}
//************** 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
//
// For Floating Licenses, this needs to be included in the Close Event of your Application
//
// the DNA_Deactivate() call requires a <password> parameter that you need
// to capture from the User
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
}