473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

compile dll with calls to methods that dont exit yet

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
Feb 17 '07 #1
2 1257
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

Feb 18 '07 #2
thanks for advice, i will giveit a go

thanks
On 18 Feb 2007 02:11:16 -0800, "Marc Gravell" <ma**********@gmail.com>
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
Feb 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Leonardo Javier Bel?n | last post by:
I cannot make the following program call the MYSQL C API when called from the function process_token and I dont know why. I checked the WEB and I did found nothing related to this bug. I am using...
5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
3
by: Phil IU Guy | last post by:
I am having 2 issues, both acting very randomly, and for the most part I dont get this message on most computers, but I have had a couple computers get either issue 1, or issue 2. Issue #1: I...
10
by: Ioannis Vranos | last post by:
In .NET multithreading we have to assign a thread to a method of a separate object each time (and not two methods of the same object)? In other words, why does this hung? #using...
26
by: Martin Jørgensen | last post by:
Hi, I don't understand these errors I get: g++ Persort.cpp Persort.cpp: In function 'int main()': Persort.cpp:43: error: name lookup of 'j' changed for new ISO 'for' scoping Persort.cpp:37:...
4
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.