Re: compile dll with calls to methods that dont exit yet



Well, reflection is *an* option, but interfaces are better;

Create a library which defines the functionality (methods, properties
etc) that your host provides. Reference this assembly from both your
host exe and your plugin dll. Now in the code where you make you host
available to the plugin, replace any class (code) references with the
interface (code) references - ideally making the plugin activation
code *also* work on interfaces.

e.g. (untested)

base assembly:

public interface IHost {
void DoSomethingHosty(int param1, string param2);
}
public interface IPlugin : IDisposable {
void Initialize(IHost host);
}
public abstract class PluginBase : IPlugin {
private readonly IHost _host;
public Host Host {get{return _host;}}
protected PluginBase() {}
protected virtual void Initialize(IHost host) {_host = host;}
public void Dispose() {Dispose(true);}
// and possibly a finalizer with Dispose(false), etc
protected virtual void Dispose(bool disposing) {}
}

plugin assembly:

public class MyPlugin : PluginBase {
void SomeRandomMethodOrEventHandler() {
Host.DoSomethingHosty(5,"abc");
}
void Initialize(IHost host) {
base.Initialize(host);
// other specific init steps
}
// override Dispose(bool) as necessary

// etc
}


host assembly:

public class MyHost : IHost, IDisposable {
public void DoSomethingHosty(int param1, string param2) {
MessageBox.Show(param1.ToString(), param2);
// whatever
}

void LoadPlugins() {
// TODO: load assembly and locate type
IPlugin plugin = (IPlugin) Activator.CreateInstance(pluginType);
plugin.Initialize(this);
myPluginCollection.Add(plugin);
}
public void Dispose() {Dispose(true);}
void Dispose(bool disposing) {
if(disposing) {
foreach(IPlugin plugin in myPluginCollection) {
try {plugin.Dispose();} catch {} // best endeavors
}
myPluginCollection.Clear();
}
}
}

***

As a random off-the-cuff third option; synamic assembly creation.
**way** OTT for this though ;-p

.



Relevant Pages

  • Re: Properties Shared Amongst Objects
    ... The host can query my application for certain ... void SetParameterValue ... void GetAmplitudeNameconst; ... My amplifier class could then look like this: ...
    (comp.object)
  • Timers and timing, was: MySQL Performance 6.0rc1
    ... Darwin 8.2.0 Power Macintosh ... per host shows the null function time value is stable to two digits, ... People who are doing timers are generally looking for one of two things, ... void null_function ...
    (freebsd-current)
  • Re: Providing a programming interface to a plugin
    ... interface that your application object implements. ... The interface that the plugin implements (in ... You have a separate interface for your host (which is contained outside ... suppose this would be similar to the office api or activeX interfaces. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: modular application
    ... Do your plugins inherit from IPlugin or do the implement it? ... the methods of this interface you would then use MethodInfo.Invoke. ... the plugin and to get the list of Services ... The Host would find that the GpsPlugin provides the GPS service and it would ...
    (microsoft.public.dotnet.languages.csharp)
  • EPIC4 remote client-side stack-based overflow(exploit)
    ... Since we can control the content of the buffer written ... void send_mes(int fd,char *host); ... void wait_connection; ... unsigned int check_version = 0; ...
    (Bugtraq)