Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从DLL调用函数_C#_Vb.net_Function_Dll_Reference - Fatal编程技术网

C# 从DLL调用函数

C# 从DLL调用函数,c#,vb.net,function,dll,reference,C#,Vb.net,Function,Dll,Reference,众所周知,您可以在dll中包含函数,引用dll,然后从主可执行文件调用函数。 我想知道反向的方法是否也可行? 因此,我喜欢从dll中调用主可执行文件中的函数,而不需要在dll中调用实际的函数。 原因:我正在开发一个插件系统。你在比较苹果和橙子:构建系统引用dll与插件系统完全不同,插件系统中的所有事情都发生在运行时。通常,您希望从插件主机(您的exe)调用某些函数的插件系统如下(简化): 是的,可执行文件可以作为引用添加到项目中,并且可以使用与从引用的DLL调用函数相同的方法 //in a co

众所周知,您可以在dll中包含函数,引用dll,然后从主可执行文件调用函数。 我想知道反向的方法是否也可行? 因此,我喜欢从dll中调用主可执行文件中的函数,而不需要在dll中调用实际的函数。
原因:我正在开发一个插件系统。

你在比较苹果和橙子:构建系统引用dll与插件系统完全不同,插件系统中的所有事情都发生在运行时。通常,您希望从插件主机(您的exe)调用某些函数的插件系统如下(简化):


是的,可执行文件可以作为引用添加到项目中,并且可以使用与从引用的DLL调用函数相同的方法

//in a common project
//functions from the host that will be callable by the plugin
public interface PluginHost
{
  void Foo();
}

//the plugin
public interface Plugin
{
  void DoSomething( PluginHost host );
}

//in the exe
class ThePluginHost : PluginHost
{
  //implement Foo
}

//in the plugin
class ThePlugin : Plugin
{
  //implement DoSomething,
  //has access to exe methods through PluginHost
}

//now al that's left is loading the plugin dll dynamically,
//and creating a Plugin object from it.
//Can be done using Prism/MEF etc, that's too broad of a scope for this answer
PluginHost host = new ThePluginHost();
Plugin plugin = CreatePluginInstance( "/path/to/dll" );
plugin.DoSomething( host );