我在 c# 中创建了一个 dll,如您所见,使用此方法:
namespace Dll
{
public class Check
{
public string JoinString(string fristName, string Lastname)
{
return fristName + " " + Lastname;
}
}
}
我构建了这个 DLL,我想在另一个应用程序中使用它,DLLImport
正如你在这里看到的:
[DllImport("Dll.dll", EntryPoint = "JoinString")]
public static extern string JoinString (string fristName, string Lastname);
private void button1_Click(object sender, EventArgs e)
{
string s = JoinString("aaa", "bbbb");
MessageBox.Show(s.ToString());
}
但我收到此错误:
An unhandled exception of type 'System.EntryPointNotFoundException' occurred in WindowsFormsApplication3.exe
Additional information: Unable to find an entry point named 'JoinString' in DLL 'Dll.dll'.
根据 MSDN:
DllImportAttribute:指示属性方法由非托管动态链接库 (DLL) 作为静态入口点公开。
您的 DLL 命名空间似乎是用 C# 编写的,它是托管代码。这将导致托管 dll。相反,您应该添加对 dll 项目的引用或利用 nuget 将您的 dll 安装到其他项目中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句