c# - 使用相同的方法名称调用多个 dll 导入

标签 c# c++ dllimport unsafe

我正在将几个非托管 C++ DLL 导入到我的项目中,但是导入的 DLL 具有相同的方法名称,这会导致编译器问题。例如;

unsafe class Myclass
{
   [DllImport("myfirstdll.dll")]
   public static extern bool ReturnValidate(long* bignum);

   [DllImport("myseconddll.dll")]
   public static extern bool ReturnValidate(long* bignum);

   public Myclass
   {
      int anum = 123;
      long passednum = &anum;
      ReturnValidate(passsednum);
   }
}

现在我想做的是重命名导入的方法。类似的东西;

[DllImport("myseconddll.dll")]
public static extern bool ReturnValidate(long bignum) AS bool ReturnValidate2(long bignum);

这可能吗?

最佳答案

使用 DllImport 属性的 EntryPoint 属性。

[DllImport("myseconddll.dll", EntryPoint = "ReturnValidate")]
public static extern bool ReturnValidate2(long bignum);

现在,当您在 C# 代码中调用 ReturnValidate2 时,您将有效地调用 myseconddll.dll 上的 ReturnValidate。

关于c# - 使用相同的方法名称调用多个 dll 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7663820/

相关文章:

c# - 从价格中删除无效字符

c# - 为什么这个颜色比较失败?

c# - 高频堆

c++ - 使 v8 对象属性和方法对 JS 可见

c# - AnsiBStr SafeArray 上的 PInvoke

c# - 停止引发 Filewatcher 控件的创建事件以自动生成原始内容的临时文件

c++ - C++ 编译器如何区分左移位/右移位和 ostream<</ostream>> 运算符?

c++ - 为什么 and(std::to_string()) 返回一个空字符串?

找不到Python dll函数

c# - C Dll 导入在 C# 中引发 Marshall 指令异常