获取异常无法在DLL'D:\ Kailash \ Code \ MyDLLS.dll'中找到名为'Say'的入口点. [英] Getting Exception Unable to find an entry point named 'Say' in DLL 'D:\Kailash\Code\MyDLLS.dll'.

查看:125
本文介绍了获取异常无法在DLL'D:\ Kailash \ Code \ MyDLLS.dll'中找到名为'Say'的入口点.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入dll.我的dll文件中有两个简单的功能.一个是Say,它接受一个字符串参数并获取字符串数据类型.另一个是Sum,它也获取字符串数据类型.
我使用dllimport类成功导入了dll文件,但问题是当我调用这两个函数时,我得到了异常无法在DLL''D:\ Kailash \ Code \ MyDLLS中找到名为"Say"的入口点.dll''.". dll的结构如下所示
命名空间:MyDLLs
课堂测试:
功能:说和总结
我正在按以下方式使用DLL.

I am trying to import dll. There are two simple function in my dll file. one is Say, which accept a string parameter and is fetching string datatype. other is Sum which also fetching string datatype.
I am getting success to import dll file using dllimport class, but problem is that when i call both function i am getting exception "Unable to find an entry point named ''Say'' in DLL ''D:\Kailash\Code\MyDLLS.dll''.". The structure of dll is given below
Namespace: MyDLLs
Class Test:
Function: Say and Sum
i am using the DLL as follow.

//Code of DLL
namespace MyDLLS
{
    public class Test
    {
        public Test()
        {
        }
        public string Say(string Name)
        {
            return "Hi " + Name + " How are you?";
        }
        public string Sum()
        {
            int x = 3;
            int y = 2;
            int xy = x * y;
            return xy.ToString();
        }
    }
}





//Code Where Using DLL 
   static class Program
    {
        [DllImport("D:\\Kailash\\Code\\MyDLLS.dll", EntryPoint = "Say", CharSet =          CharSet.Auto)]
        public static extern string Say(string Name);
        [DllImport("MyDLLS.dll", EntryPoint = "Sum", CharSet = CharSet.Auto)]
        public static extern string Sum();


        static void Main(string[] args)
        {
            string nm = Console.ReadLine().ToString();
            Console.WriteLine(Say(nm));

            Console.WriteLine(Sum());
            Console.ReadLine();

        }
    }
}



请帮帮我,
Kailash



Please help me,
Kailash

推荐答案

由于它们都是用C#编写的,因此您无需进行DllImport导入.删除四行:
Since they are both written in C#, you don''t need to DllImport anything. Take the four lines out:
[DllImport("D:\\Kailash\\Code\\MyDLLS.dll", EntryPoint = "Say", CharSet =          CharSet.Auto)]
public static extern string Say(string Name);
[DllImport("MyDLLS.dll", EntryPoint = "Sum", CharSet = CharSet.Auto)]
public static extern string Sum();


并包含对您的引用,而不是Dll.然后,您可以直接通过MyDLLS.Say进行引用,也可以添加using语句.

顺便说一句:除非您将方法声明为static,否则您将需要提供类实例引用以始终访问方法.


And include a reference to you Dll instead. You can then either refer directly via MyDLLS.Say or by adding a using statement.

BTW: unless you declare the method as static you will need to provide a class instance reference to access the methods anyway.


这篇关于获取异常无法在DLL'D:\ Kailash \ Code \ MyDLLS.dll'中找到名为'Say'的入口点.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆