Licensing in the Run-Time Object

The run-time verification process is illustrated below:

When the application is started, the ActiveX designer's run-time object typically needs to be created. Before doing so, the application must verify that the ActiveX designer is licensed for the machine. It calls CreateInstanceLic, passing the embedded license key as a parameter.

CreateInstanceLic compares the embedded string with the ActiveX designer's copy saved with the run-time object's class factory. If the strings match, CreateInstanceLic creates an instance of the run-time object; the returned status reflects the success or failure of the instance creation. If the strings do not match, CreateInstanceLic returns CLASS_E_NOTLICENSED.

The following sample shows an implementation of CreateInstanceLic:

STDMETHODIMP CClassFactory::CreateInstanceLic
(
    IUnknown *pUnkOuter,
    IUnknown *pUnkReserved,
    REFIID    riid,
    BSTR      bstrKey,
    void    **ppvObjOut
)
{
    BOOL  fMatch;

    *ppvObjOut = NULL;

    // See if the key given matches.
    fMatch = ( 0 == lstrcmpW(g_wszLicenseKey, bstrKey));
    if (!fMatch)
        return CLASS_E_NOTLICENSED;

    // If it does, create the object. 
    return CreateOleObjectFromIndex(pUnkOuter, m_iIndex, 
            ppvObjOut, riid);
}

CreateInstanceLic is similar to IClassFactory::CreateInstance, except that it adds the license key verification.

If the host passes a key that indicates more restricted capabilities than the user or machine license allows, the ActiveX designer should provide only the limited capabilities for the newly created instance, as if the user or machine license had not been previously verified.