从c#dll读取方法

时间:2015-11-21 14:52:40

标签: c# dll

我已将以下代码编译到程序集文件 test.dll

namespace dll_test
{
    public class Class1
    {
        public int DoMagic()
        {
            return 12;
        }
    }
}

我想使用 DLL导出查看器检查我的dll,但是当我这样做时,我看不到任何功能。

enter image description here

问题出在哪里?

1 个答案:

答案 0 :(得分:3)

您必须将您的功能添加到dll-export表中。在此表中是您可以在可执行文件中使用的所有函数的名称。要在C#中执行此操作,您必须添加非托管导出(DllExport for .Net)(https://www.nuget.org/packages/UnmanagedExports)。

然后在静态方法中添加DllExport,如下所示:

[DllExport("DoMagic", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
public static int DoMagic()
{
  return 12;
}

您可以找到有关https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports#TOC-C-:或msdn:https://msdn.microsoft.com/en-us/library/z4zxe9k8.aspx

的更多信息
相关问题