Contents - Index


4.2.2.5 Case Study - Reusing the Code from the Demo Project

Overview

  1. Look at the example code supplied with the Sheriff SDK (which can be found in \demo\dll\local etc.).
  2. Copy the appropriate parts of the example code into your application.
  3. If you have your own Sheriff Product ID you should replace the Product ID in the copied sample code with your own.
  4. Build your application
  5. Run the application to check that it works

Detailed step-by-step instructions.

The following is a set of detailed step-by-step instructions for adding copy protection to a Visual C++ application. All of the code samples shown can be found in the API\API\DEMO SOURCE\VC directory that contains the source code for the demonstration application.

1. Copy the .h and .lib files from the API\API\VC directory into the appropriate places within your application's project directory

2. Copy the following header files from the API\API\DEMO SOURCE\VC directory to your project directory:

exceeddlg.h
exportdlg.h
registerdlg.h
renewdlg.h
sheriff.h
slsapi.h

3. Copy the following source files from the API\API\DEMO SOURCE\VC directory to your project directory:

ExceedDlg.cpp
ExportDlg.cpp
LicenceDlg.cpp
RegisterDlg.cpp
RenewDlg.cpp
Sheriff.cpp

4. Open your application in the Visual C++ development environment.

5. Add the files you copied across in Step 3 to your project. The m_pSheriff->Register call in the RegisterProduct() method should be changed to mention the name of your application rather than the Sheriff Demo.

6. Add the SlsLib.lib file to the Link settings of your Release build. This will statically link the Sheriff SDK into your code.

7. Add the SlsLibD.lib file to the Link settings of your Debug build.

8. Copy the following methods from the CWinApp derived class in SlsDemo.cpp file (in the API\API\DEMO SOURCE\VC directory) to your own CWinApp derived class:

CSlsDemoApp::CheckLicence()
CSlsDemoApp::RegisterLicence()
CSlsDemoApp::RegisterProduct()
CSlsDemoApp::ShowSheriffError()

9. Near the top of this file place the Sheriff Product ID and Secret Codes for your application. If you do not yet have your own Product ID and Secret Codes you can use the evaluation versions.

10. At the top of your file place the following includes:

#include "ExportDlg.h"
#include "SlsApi.h"
#include "RegisterDlg.h"
#include "RenewDlg.h"
#include "ExceedDlg.h"
#include "LicenceDlg.h"

11. From the CSlsDemoApp Class definition in the SlsDemo.h header file (in the API\API\DEMO SOURCE\VC directory) copy the following lines to your own CWinApp derived class definition:

CSheriff    *m_pSheriff;
BOOL    m_bLicenceOK;
BOOL    m_nAccessKey;
CString    m_strUserName;

BOOL  CheckLicence();
BOOL  RegisterProduct();
BOOL  RegisterLicence();

BOOL  m_bRunInDemoMode;
void  RunInDemoMode() { m_bRunInDemoMode=TRUE; }
void  ShowSheriffError();

12. Add the following include to your header file:

#include "sheriff.h"

13. Add the dialog resources from the SlsDemo project to your own project (these are used by the Sheriff SDK and allow you to create customized versions of your own).

14. Add the following lines of code to your CWinApp derived class contructor:

m_pSheriff=NULL;
m_bRunInDemoMode=FALSE;
m_bLicenceOK=FALSE;
m_nAccessKey=0;

15. Add the following to your class destructor:

delete m_pSheriff;

16. Add this to your ExitInstance method:

if(!m_bRunInDemoMode)
{

SLS_RELEASE Release;
memset(&Release,0,sizeof(Release));
Release.UnitsConsumed=0L;
m_pSheriff->Release(Release);
}
delete m_pSheriff;
m_pSheriff=NULL;
return CWinApp::ExitInstance();

17. Add this to your InitInstance method:

//Change the registry key under which the Sheriff settings are stored.
// IMPORTANT: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Sheriff Demo"));

m_pSheriff=new CSheriff(g_szProductID,m_strUserName);
if(!m_pSheriff->Succeeded())
{

ShowSheriffError();
return FALSE;
}
m_pSheriff->SetSecrets(g_arySecrets);
if(!m_pSheriff->IsProductLicensed())
{
RegisterProduct();
//If you want to automaticlly issue a trial licence
//enble the following code
/*------------------------------------------------------
//Issue a 30-day, single-user, standalone trial licence
SLS_LICENCE TrialLicence;
memset(&TrialLicence,0,sizeof(SLS_LICENCE));
TrialLicence.Type = SLS_TYPE_TIME_METER|SLS_TYPE_CONCURRENCY|SLS_TYPE_STANDALONE;
TrialLicence.Meter=30;   //30 day
TrialLicence.CoUsers=1;  //1 user only
if(!m_pSheriff->License(TrialLicence))
{
ShowSheriffError();
return FALSE;
}
---------------------------------------------------------*/
}
if (!CheckLicence()) return FALSE;

Don't forget to change the name passed to the SetRegistryKey function to something appropriate to your company.

18. Build your project.

19. The first time you run your application it will register itself and display a dialog box that lets you either enter a licence key or continue running as a demo application.

These instructions show one way of adding copy protection to a C++ application (based on the demo application supplied with the SDK). See elsewhere in this help file for information about the other ways.

Now that you have a version of your application that uses Sheriff copy protection you can go over the code you added and make any necessary changes to customise the implementation