HRESULT CNxOCXControlSite::CreateInstanceLic( CNxOCXControl* pWndCtrl, REFCLSID
clsid, LPUNKNOWN pUnkOuter, DWORD dwClsCtx, REFIID iid, LPVOID* ppv, BSTR bstrLicKey )
{
//-- Do you specified the correct ocx-Control Library in CNxOCXControl::CreateControl ?
ASSERT( pWndCtrl!=NULL && pWndCtrl->m_hInstLibrary!=NULL );
if ( pWndCtrl==NULL || pWndCtrl->m_hInstLibrary==NULL )
return CO_E_ERRORINDLL;
DLLGETCLASSOBJECTFUNC pDllGetClassObject = (DLLGETCLASSOBJECTFUNC)::GetProcAddress( pWndCtrl->m_hInstLibrary, _T("DllGetClassObject") );
if ( pDllGetClassObject==NULL )
return CO_E_ERRORINDLL;
HRESULT hr;
if ( bstrLicKey == NULL )
{
LPCLASSFACTORY pClassFactory = NULL;
hr = pDllGetClassObject(
clsid, IID_IClassFactory, (void**)&pClassFactory );
if ( SUCCEEDED(hr) )
{
hr = pClassFactory->CreateInstance(pUnkOuter, iid, ppv);
pClassFactory->Release();
}
}
else
{
LPCLASSFACTORY2 pClassFactory = NULL;
hr = pDllGetClassObject(
clsid, IID_IClassFactory2, (void**)&pClassFactory );
if ( SUCCEEDED(hr) )
{
hr = pClassFactory->CreateInstanceLic(pUnkOuter, NULL, iid, bstrLicKey, ppv );
pClassFactory->Release();
}
}
return hr;
}