Contents - Index


4.2.4 CSheriff Class Reference

CSheriff is a shrink-wrapper class of the Sheriff Licensing System API. The reference lists the member methods and explains in brief their functionality. Detailed discussion on API functions can be found in Sheriff API Reference.

Construction

CSheriff(LPCTSTR lpszProductID,LPCTSTR lpszUserName);

Construct a CSheriff object. lpszProductID points to a null-terminated string which identifies the product, lpszUserName points to a null-terminate string containing the user's name.

NB. The user name passed to the CSheriff constructor, or the SLS_Request function cannot be longer than 31 characters (32 including the null-terminator).

Set Product Secrets

Void SetSecrets(SLS_SECRET *parySecrets,int nSizeSecrets=4);

Sets Product Secret Codes. parySecrets points to an array of secrets, by default the size of the array is 4. Product Secrets are required only if you want to implement challenge protocol.

Example:

SLS_SECRET Secrets[4]=

{

      "0763-1985-3207-6621

      "1854-2076-4198-7532

      "2482-1593-2604-4927

      "3739-0628-9517-9618

};


CSheriff *pSheriff=new CSheriff("9758-3050-1918-9292-6466","John Smith");

Sheriff->SetSecrets(Secrets);

Get User Reference Code

BOOL GetReference(CString &strReference);

Returns a one-time user reference code.

Authorise Licence Key

BOOL SetLicence(LPCSTR pszReference,LPCTSTR lpszLicenceKey);

Authorise licence key on the user's machine. Reference must be provided through pszReference which is returned by calling GetReference.

Register Product

BOOL Register(LPCTSTR lpszProductName, LPCTSTR lpszLicencePath);

Registers a new product on the user's machine. lpszProductName points to a string identifying the product's name, lpszLicencePathpoints to a full path where licence files will be stored or have been stored.

License Product Programmatically

BOOL License(SLS_LICENCE Licence);

License is called to issue a licence from the application without user's intervention. The difference between SetLicence and License is that SetLicence requires a Reference Code and Licence Key, whereas License can issue a licence straight away. SetLicence must be called in challenge mode. SetLicence is often called once by application installation program to issue a trial licence.

Request Licence to Run the Application

BOOL Request(SLS_REQUEST Request,SLS_PERMIT &Permit);

Request is called by the application to apply for permission to run the application.

Update Licence State

BOOL Update(SLS_UPDATE Update,SLS_PERMIT &Permit);

Update is called periodically by the application to notify Sheriff that the licence is still being used and also update Sheriff on the usage of the licence.

Release Licence

BOOL Release(SLS_RELEASE Release);

Release is called by the application to notify Sheriff that the application exits. Sheriff will then release the licence and make it ready to be taken by other applications.

Succeeded or Failed?

BOOL Succeeded();

Succeeded indicates whether the last function call is successful or not.

Get Last Error Code

HRESULT GetLastError();

Returns the error code caused by last operation.

Get Last Error Message

void GetLastErrorMessage(CString &strError);

Returns the last error message.