使用RGiesecke.DllExport在C#DLL中没有函数

run*_*man 7 c# dll unmanaged

我正在尝试在C#中创建一个DLL,以便在其他几种语言中使用.我找到了RGiesecke的DllExport,但似乎没有用.它构建得很好并且创建了一个dll,但是当我在Dependency Walker中打开它时它没有显示任何函数,我的调用代码也找不到它们.

我创建了一个新的"类库"项目(VS 2013),然后从NuGet安装了"Unmanaged Exports(DllExport for .Net)".我需要任何项目设置吗?

这是我的代码.

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;

namespace ToolServiceDLL
{
    public class Class1
    {
      [DllExport("addUp", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
      public static double addUp(double num1, double num2)
      {
        return num1 + num2;
      }

      [DllExport("get5", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
      public static int get5()
      {
        return 5;
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

run*_*man 9

我发现了这个问题.它在RGiesecke文档中有它,但我错过了它.在项目设置 - >构建 - >平台目标中:您不能将其设置为"任何CPU".您必须将其设置为x64或x86,具体取决于您是否要在64位或32位应用程序中使用它.