public static CLRLicenseContext CreateRuntimeContext(Type type, string key) { var cxt = new CLRLicenseContext(type, LicenseUsageMode.Runtime); if (key != null) { cxt.SetSavedLicenseKey(type, key); } return(cxt); }
// The CLR invokes this whenever a COM client invokes // IClassFactory::CreateInstance() or IClassFactory2::CreateInstanceLic() // on a managed managed that has a LicenseProvider custom attribute. // // If we are being entered because of a call to ICF::CreateInstance(), // fDesignTime will be "true". // // If we are being entered because of a call to ICF::CreateInstanceLic(), // fDesignTime will be "false" and bstrKey will point a non-null // license key. private static object AllocateAndValidateLicense(RuntimeTypeHandle rth, IntPtr bstrKey, int fDesignTime) { Type type = Type.GetTypeFromHandle(rth); CLRLicenseContext licensecontext = new CLRLicenseContext(fDesignTime != 0 ? LicenseUsageMode.Designtime : LicenseUsageMode.Runtime, type); if (fDesignTime == 0 && bstrKey != (IntPtr)0) { licensecontext.SetSavedLicenseKey(type, Marshal.PtrToStringBSTR(bstrKey)); } try { return(LicenseManager.CreateWithContext(type, licensecontext)); } catch (LicenseException lexp) { throw new COMException(lexp.Message, CLASS_E_NOTLICENSED); } }
private static object AllocateAndValidateLicense(RuntimeTypeHandle rth, IntPtr bstrKey, int fDesignTime) { object obj2; Type typeFromHandle = Type.GetTypeFromHandle(rth); CLRLicenseContext creationContext = new CLRLicenseContext((fDesignTime != 0) ? LicenseUsageMode.Designtime : LicenseUsageMode.Runtime, typeFromHandle); if ((fDesignTime == 0) && (bstrKey != IntPtr.Zero)) { creationContext.SetSavedLicenseKey(typeFromHandle, Marshal.PtrToStringBSTR(bstrKey)); } try { obj2 = LicenseManager.CreateWithContext(typeFromHandle, creationContext); } catch (LicenseException exception) { throw new COMException(exception.Message, -2147221230); } return(obj2); }
// The CLR invokes this whenever a COM client invokes // IClassFactory::CreateInstance() or IClassFactory2::CreateInstanceLic() // on a managed managed that has a LicenseProvider custom attribute. // // If we are being entered because of a call to ICF::CreateInstance(), // fDesignTime will be "true". // // If we are being entered because of a call to ICF::CreateInstanceLic(), // fDesignTime will be "false" and bstrKey will point a non-null // license key. private static object AllocateAndValidateLicense(RuntimeTypeHandle rth, IntPtr bstrKey, int fDesignTime) { Type type = Type.GetTypeFromHandle(rth); CLRLicenseContext licensecontext = new CLRLicenseContext(fDesignTime != 0 ? LicenseUsageMode.Designtime : LicenseUsageMode.Runtime, type); if (fDesignTime == 0 && bstrKey != (IntPtr)0) { licensecontext.SetSavedLicenseKey(type, Marshal.PtrToStringBSTR(bstrKey)); } try { return LicenseManager.CreateWithContext(type, licensecontext); } catch (LicenseException lexp) { throw new COMException(lexp.Message, CLASS_E_NOTLICENSED); } }
private static object AllocateAndValidateLicense(RuntimeTypeHandle rth, IntPtr bstrKey, int fDesignTime) { object obj2; Type typeFromHandle = Type.GetTypeFromHandle(rth); CLRLicenseContext creationContext = new CLRLicenseContext((fDesignTime != 0) ? LicenseUsageMode.Designtime : LicenseUsageMode.Runtime, typeFromHandle); if ((fDesignTime == 0) && (bstrKey != IntPtr.Zero)) { creationContext.SetSavedLicenseKey(typeFromHandle, Marshal.PtrToStringBSTR(bstrKey)); } try { obj2 = LicenseManager.CreateWithContext(typeFromHandle, creationContext); } catch (LicenseException exception) { throw new COMException(exception.Message, -2147221230); } return obj2; }