License and dlls

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

License and dlls

Post by qcrnd » Mon May 04, 2009 9:53 am

Hi
I have a dll file that works with TeeChart and I built it with a license.licx file.
I would like to enable applications to work with my dll but it seems that any application that wants to work with my dll must compile with the license.licx as well otherwise nothing will work.
That doesnt seem logical that whoever wants to use my dll must compile with the license.licx . Isnt it enough that my dll was built with a license.licx file

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon May 04, 2009 10:19 am

Hi qcrnd,

In that case you may be interested using TeeChart with plugin configuration as described here:

Using TeeChart in a plugin dll

The standard version of TeeChart for .NET supports license control for use in a dynamically loaded plugin. The plugin would typically be an assembly that contains TeeChart and that may be loaded dynamically at runtime by a container application using the NET 'Assembly.Load' method or similar. To permit the container application to load and run TeeChart without requiring a licenses.licx file at container level TeeChart offers an alternative to default constructor by which the dll assembly in which it is compiled passes itself as an argument and license checks are made at the level of the dll not at the container application. Please note that the container application may not make code calls directly to TeeChart. It may open and run the TeeChart dll whilst that dll is autonomous in nature, making its own calls to TeeChart. The exception to that rule, allowing Chart calls to be made from the container application, would be if methods of TeeChart are 'wrapped' (secondarily called) by methods that may be defined in an independant interface. The example described here could be modified to include such calls.

The plugin
The plugin that houses TeeChart would load TeeChart passing itself as argument when created. The overloaded constructor need only be used the first time that TeeChart is opened, to permit the license check to take place. Thereafter TeeChart may be used via conventional means. An example of use would be the following. In this example a 'dummy' creation of TeeChart is made at form create to force the initial license check.

Example:
In this example, PluginShared.Factory is an interface, referenced by the host application, that offers up a method called 'CreateForm'. The Assembly that houses TeeChart implements PluginShared.Factory and thus also offers up the CreateForm method but with its own implementation (in which it loads TeeChart). The host recognises the CreateForm method call without requiring knowledge of the TeeChart specific assembly.

Please note. The Assembly that houses TeeChart must contain a Licenses.licx file and be compiled on a machine with a valid TeeChart Developer License.

Assembly housing TeeChart (eg. PluginWithTeeChart.dll)
-------------------------------------------------------------------------------------------
Class:

Code: Select all

namespace Plugin
{
   public class FactoryImpl : PluginShared.Factory  
    {
        public System.Windows.Forms.Form CreateForm()
        {
            try
            {
                return new PluginWithTeeChart.FormWithChart();
            }
            catch (Exception e)
            {
                MessageBox.Show("failed to create plugin with error: " + e.ToString());
                return null;
            }
        }
    }
}
Form:

Code: Select all

namespace PluginWithTeeChart
{
    public partial class FormWithChart : Form
    {
        public FormWithChart()
        {
            //discardable Chart forces License check
            Steema.TeeChart.TChart tempChart = new Steema.TeeChart.TChart(this);
            tempChart = null;
            InitializeComponent(); //<---- Normal application code. Could run here various TeeCharts without need for overloaded constructor
        }
    }
}

The container application (eg. HostApp.exe)
----------------------------------------------------------------------
The container might load the TeeChart housing assembly (dll) in the following way. It is important that HostApp reference the common interface Plugin.FactoryImpl that publishes the CreateForm method.

Code: Select all

void LoadTeeChartPlugin(string pluginName)
{
  string pluginName = @"myFolderPluginWithTeeChart.dll";
  try
  {
    Debug.WriteLine("Loading plugin assembly " + pluginName);

    Assembly assembly = Assembly.LoadFrom(pluginName);

    string factoryTypeName = "Plugin.FactoryImpl";

    Type t = assembly.GetType(factoryTypeName);
    if (t == null)
    {
      MessageBox.Show("Type: " + factoryTypeName + " not found in plugin assembly");
      return;
    }

    PluginShared.Factory factory = (PluginShared.Factory)assembly.CreateInstance(t.ToString());
    System.Windows.Forms.Form f = factory.CreateForm();
    f.ShowDialog();
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.ToString());
  }
}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Post by qcrnd » Mon May 04, 2009 11:42 am

Hi Narcis
Looks good .
Thanks very much
Ryan

Post Reply