我遇到了一个问题,我真的可以告诉你我需要帮助。我有一个库,它有一些我需要的方法。但是当我将它添加为引用时,抛出这个错误:
lib.dll could not be added. Please make sure that the file is accessible, and that it is a valid assambly or COM component.
我可以告诉你,我不知道是用哪种语言写的,但事实并非如此。我在我工作的一个项目中看到有人使用保留字 Lib在具有相同 Lib 的 Visual Basic 中,它对他来说效果很好。他可以使用 lib 的资源,但问题是他是用 Visual Basic 开发的,而我对 Visual Basic 一无所知,只知道 C#。
他是这样做的
Public Function Amethod Lib "theDLLfile" (ByVal s as String) As String...
问题是:那能做到吗?如何借鉴和使用其方法? Lib 词的作用是什么以及如何使用它?
我真的需要帮助。
小更新:
引用DLL时,url可以是绝对的还是相对的?
最佳答案
这是在 VB 中执行 DllImport 的旧方法。您还忘记了“声明”关键字。 VB 代码应如下所示:
Public Declare Function Amethod Lib "theDLLfile" (ByVal s as String) As String
C# 中的等价物是:
[System.Runtime.InteropServices.DllImport("theDLLfile")]
public static extern string Amethod(string s);
现在在 VB 中通常的做法是:
<System.Runtime.InteropServices.DllImport("theDLLfile")>
Public Shared Function Amethod(ByVal s As String) As String
End Function
关于c# - 如何在 C# 中像 Visual Basic 一样使用 Lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17087366/