将托管功能导出为非托管

时间:2013-10-23 14:57:36

标签: c#

我正在尝试使用(https://www.nuget.org/packages/UnmanagedExports)导出我的一些函数,但它似乎没有用。

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace Verificare
{

    static class Exports
    {
        [DllExport]
        public static void Salut()
        {
        }
    }
}

我正在使用DLL EXPLORER来查看导出的函数,不幸的是,在我的dll中没有导出的函数。

1 个答案:

答案 0 :(得分:2)

在这里尝试并验证,它按预期工作:

  • 创建类库项目
  • 从NuGet
  • 添加了包
  • 将配置更改为x86

创建了一些功能:

using RGiesecke.DllExport;

namespace ClassLibrary1
{
    public static class Class1
    {
        [DllExport]
        public static int Hello()
        {
            return 1;
        }

        [DllExport]
        public static void Nope()
        {
        }
    }
}

如您所见,功能正确导出:

enter image description here

如果有疑问,请使用CFF Explorer检查DLL,尝试新项目。

注意:当您创建项目的另一个配置时,输出不在bin \ Debug中,而是在bin \ x86 \ Debug中,请确保您正在检查正确的DLL。