private static int RequestLicKey(RuntimeTypeHandle rth, ref IntPtr pbstrKey)
{
Type type = Type.GetTypeFromHandle(rth);
License license;
string licenseKey;
// license will be null, since we passed no instance,
// however we can still retrieve the "first" license
// key from the file. This really will only
// work for simple COM-compatible license providers
// like LicFileLicenseProvider that don't require the
// instance to grant a key.
//
if (!LicenseManager.ValidateInternalRecursive(LicenseManager.CurrentContext,
type,
null,
false,
out license,
out licenseKey))
{
return E_FAIL;
}
if (licenseKey == null)
{
return E_FAIL;
}
pbstrKey = Marshal.StringToBSTR(licenseKey);
if (license != null)
{
license.Dispose();
license = null;
}
return S_OK;
}