代码之家  ›  专栏  ›  技术社区  ›  Ehsan Akbar

在dll'dll.dll'中找不到名为'joinstring'的入口点。在C中#

  •  -1
  • Ehsan Akbar  · 技术社区  · 6 年前

    我在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'.
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   AotN    6 年前

    根据MSDN:

    dllimportattribute属性 :指示非托管动态链接库(dll)将属性化方法公开为静态入口点。

    您的dll命名空间似乎是用托管代码c编写的。这将导致托管dll。相反,您应该添加对dll项目的引用,或者利用nuget将dll安装到其他项目中。