Ok, I've figured out how to write an .NET web service that uses the VB6 version of ActiveLock 3.6.1 to properly activate against the VB6 version. If anyone had tried to use the VB6 DLLs in a .NET web project before they probably received this error when attempting to create new instances of the ActiveLock interfaces:
System.Runtime.InteropServices.COMException was unhandled
Exception from HRESULT: 0x800A0062
To fix this issue you must run all VB6 DLL calls in a single-threaded apartment thread. To do this, you first need to place all ActiveLock VB6 DLL calls in a separate class. For example:
public class ActiveLockGenerator
{
string m_installation_code;
string m_app_name;
string m_app_version;
string m_software_code;
string m_features;
string m_products_path;
string m_activation_code;
EventWaitHandle m_event_wait_handle;
public ActiveLockGenerator(EventWaitHandle event_wait_handle, string products_path, string installation_code, string app_name, string app_version, string software_code, string features)
{
m_installation_code = installation_code;
m_app_name = app_name;
m_app_version = app_version;
m_software_code = software_code;
m_features = features;
m_products_path = products_path;
m_event_wait_handle = event_wait_handle;
}
public void GenerateActivationCode()
{
try
{
ActiveLock3.IALUGenerator GeneratorInstance;
ActiveLock3.AlugenGlobals AlugenGlobals = new ActiveLock3.AlugenGlobals();
ActiveLock3.ProductInfo ProductInfo = new ActiveLock3.ProductInfo();
ActiveLock3.Globals Globals = new ActiveLock3.Globals();
ActiveLock3.ProductLicense ProductLicense;
// Generate activation code
ProductLicense = Globals.CreateProductLicense(m_app_name, m_app_version, m_software_code, ActiveLock3.LicFlags.alfSingle, ActiveLock3.ALLicType.allicPermanent, "", m_features, DateTime.Now.AddDays(365), "", DateTime.Now, "", 1, "");
ActiveLock3.ProductsStoreType store_type = ActiveLock3.ProductsStoreType.alsINIFile;
GeneratorInstance = AlugenGlobals.GeneratorInstance(ref store_type);
GeneratorInstance.StoragePath = m_products_path;
ProductInfo = GeneratorInstance.RetrieveProduct(app_name, app_version);
m_activation_code = GeneratorInstance.GenKey(ref ProductLicense, m_installation_code, m_features) + "aLck" + m_installation_code;
}
catch (Exception ex)
{
m_activation_code = ex.Message;
}
m_event_wait_handle.Set();
}
public string GetActivationCode()
{
return m_activation_code;
}
}
After setting up the above you can activate by using this code:
AutoResetEvent event_wait_handle = new AutoResetEvent(false);
ActiveLockGenerator active_lock_gen = new ActiveLockGenerator(event_wait_handle, Server.MapPath("~") + "\\products.ini", installation_code, features);
// Execute our ActiveLock calls in a single-threaded apartment thread
Thread thread = new Thread(new ThreadStart(active_lock_gen.GenerateActivationCode));
thread.SetApartmentState(ApartmentState.STA);
// Start the thread and wait for it to finish
thread.Start();
event_wait_handle.WaitOne();
event_wait_handle.Reset();
activation_code = active_lock_gen.GetActivationCode();
- Houdini