![](/img/trans.png)
[英]How to properly load an instance from a DLL implementing a specific base class in C#?
[英]Load a Specific class from dll in C#
我只想從給定的dll加載某些類。 問題如下:
我有以下dll文件。
DLL 1:
命名空間:
DLL 2:
命名空間:
如上面的示例所示,我有2個甚至更多個具有相同類的dll是有可能發生的。 (請注意,名稱空間相同)
現在我想到了以下幾點:
有什么辦法可以做這樣的事情嗎?
您有兩個不同的dll文件。 因此,您可以將兩個不同的dll文件導入到C#項目中。 例如,第一個dll文件的名稱為“ File1”,第二個dll文件的名稱為“ File2”
const string file1_Dll_Path = @"File1.dll";
const string file2_DllPath = @"File2.dll";
[DllImport(file2_DllPath, CallingConvention = CallingConvention.Cdecl)]
public static extern int YOURFUNCTIONINFILE2DLL();
[DllImport(file1_Dll_Path, CallingConvention = CallingConvention.Cdecl)]
public static extern void YOURFUNCTIONINFILE1DLL();
注意:不要忘記添加“不安全”的C#表單。 像這樣
unsafe public partial class FORMNAME : Form
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.