gpt4 book ai didi

c# - 将托管功能导出到非托管

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:50 25 4
gpt4 key购买 nike

我正在尝试使用 ( 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 中没有导出函数。

最佳答案

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

  • 创建了一个类库项目
  • 从 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。

关于c# - 将托管功能导出到非托管,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19545274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com