Protect a VC++ app with Quick License Manager

Following is a step-by-step procedure to protect a VC++ app (unmanaged C++). Note that the steps below assume you have a QLM License Server already setup.

1. Launch the QLM Management Console

2. Create a product from the “Define Product” tab or use the Demo 1.0 product if you are evaluating QLM.

3. Go to the "Protect your application tab":

  • Page 1: Select the product to protect and the License Server

  • Page 2: Select "VC++"

  • Page 3: Leave the default settings or customize the look & feel if needed. By default, QLM will bind the license to the Computer Name. You can select the binding of your choice by setting the QlmLicenseBinding property located in the section "6. Qlm License Properties".

  • Page 4a: Select the folder where your VC++ source code is located and click Save

  • Page 4b: Click Update Visual Studio Project and locate your *.vcxproj file. If this step fails, you can ignore the error and do the following to update your Visual Studio project:

    • Add LicenseValidator.cpp and LicenseValidator.h to your project

    • Copy QlmLicenseLib.dll, QlmLicenseLib.dll.manifest and QlmLicenseWizard.exe to your bin folder from where your application runs. These files can be found in: C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\net4.0

  • Copy the generated XML file (YourProduct.lw.xml) to your bin folder from where your application runs.

  • Page 5: Click Finish

5. Open your VC++ project in Visual Studio

6. Add the following to your main view header file:

private:
LicenseValidator *m_lv;
void FreeResources();
void LaunchLicenseWizard ();
CString wizardSettingsFile; 

7. Add the following code to your main view cpp file, in the OnInitialUpdate method:

void CYourClass::OnInitialUpdate()
{
    CView::OnInitialUpdate(); // remove this line if you are not using a Windowed app.
    m_lv = new LicenseValidator();
    // Rename Demo 1.0.lw.xml to your app's xml file and make sure the file is copied to the binary folder
    PathAppend(wizardSettingsFile.GetBuffer(MAX_PATH), m_lv->GetThisModuleFolder());
PathAppend(wizardSettingsFile.GetBuffer(MAX_PATH), _T("Demo 1.0.lw.xml"));
wizardSettingsFile.ReleaseBuffer();
    ELicenseBinding licenseBinding = ELicenseBinding_ComputerName;
    bool needsActivation = false;
    CString returnMsg ("");
    if (m_lv->ValidateLicenseAtStartup(licenseBinding, needsActivation, returnMsg) == FALSE)
    {
        this->LaunchLicenseWizard();
        if (m_lv->ValidateLicenseAtStartup(licenseBinding, needsActivation, returnMsg) == FALSE)
        {
            FreeResources ();
            ExitProcess (0);
        }
    }
}
void CYourClass::FreeResources()
{
    if (m_lv != NULL)
    {
        delete m_lv;
        m_lv = NULL;
    }
}
void CYourClass::LaunchLicenseWizard ()
{
    CString strLicenseWizardExe (_T("C:\\Program Files\\Soraco\\QuickLicenseMgr\\QlmLicenseWizard.exe"));
    if (FileExists(strLicenseWizardExe) == false)
    {
        // If not found, assume the wizard was installed in the same folder as the current app/module
        strLicenseWizardExe = m_lv->GetThisModuleFolder();
        PathAppend(strLicenseWizardExe.GetBuffer(MAX_PATH), _T("QlmLicenseWizard.exe"));
        strLicenseWizardExe.ReleaseBuffer();
        if (FileExists(strLicenseWizardExe) == false)
        {
            CString msg;
            msg.Format(_T("The file %s does not exist."), strLicenseWizardExe);
            ::MessageBox(NULL, msg, _T("QlmLicenseWizard"), MB_OK);
            return;
        }
    }
    CString strArgs;
    // Configure the settings files - update the name of the settings file below
    if (FileExists(wizardSettingsFile) == true)
    {
        strArgs += " /settings \"";
        strArgs += wizardSettingsFile;
        strArgs += "\"";
    }
    m_lv->license->LaunchProcess(_bstr_t(strLicenseWizardExe), _bstr_t(strArgs), VARIANT_TRUE, VARIANT_TRUE);
}
 
bool CYourClass::FileExists (const CString &strFileName)
{
return _taccess (strFileName, 4) ? false : true;

}

This completes the integration. The next time you open your VC++ application the OnInitialUpdate method should get triggered and perform the license validation.

To generate a license key for testing purposes:

  • Go to the Manage Keys tab.

  • Click "Create Activation Key"

  • Select the Product (Demo 1.0 for trials) and click OK.

  • Copy and Paste the generated Activation Key in the License Wizard launched when your application starts up and follow the steps in the wizard.

The files that you need to distribute with your application are:

  • QlmLicenseLib.dll

  • QlmLicenseLib.dll.manifest

  • QlmLicenseWizard.exe

  • XML file generated by the Protect Your Application Wizard

Troubleshooting Tips

If you run into compilation issues after adding the LicenseValidator class to your project, you can try the following:

  • include atlstr.h in LicenseValidator.h

  • include io.h in LicenseValidator.h

  • Define UNICODE in the pre-processor args (in VS project properties).

  • Add 'version.lib' to Additional Dependencies (in VS project properties).

  • If the <strongname.h> file is missing, download and install the .NET 4.8 Developer Pack.

Last updated