PC Review


Reply
Thread Tools Rate Thread

compile dll with calls to methods that dont exit yet

 
 
Peted
Guest
Posts: n/a
 
      17th Feb 2007
if you are writing a dll that is to be load of hdd from the main
application, and instantiated using latebinding and reflection by the
main aplication, how do you compile the DLL you are writing when it
referers to methods and properties that only exist in the main
aplication ?

i cant use the option to link the debuggin proccess to a running exe,
becasue the hosting program wants the user to manually load the dll
using a dialogue box

any advice please
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      18th Feb 2007
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

 
Reply With Quote
 
Peted
Guest
Posts: n/a
 
      18th Feb 2007
thanks for advice, i will giveit a go

thanks


On 18 Feb 2007 02:11:16 -0800, "Marc Gravell" <(E-Mail Removed)>
wrote:

>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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoiding Compile Error for Unsupported Methods Kevin Microsoft Excel Programming 2 22nd Dec 2008 10:23 PM
Compile/Link problem when using calls into Excel from C# VS 2005 Norbert M Microsoft C# .NET 0 24th Jul 2008 07:05 AM
I dont know about incoming calls when connected thru modem =?Utf-8?B?bWFp?= Windows XP General 1 21st Mar 2005 07:03 AM
VS Hangs on Compile or Exit Selden McCabe Microsoft Dot NET 0 4th Aug 2004 03:18 PM
Opening a file in VS2002 actually calls form methods? Mike Microsoft Dot NET Framework Forms 0 7th Aug 2003 02:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:09 PM.