【问题标题】:DllExport not creating an entry pointDllExport 未创建入口点
【发布时间】:2015-03-03 22:00:50
【问题描述】:

我正在尝试使用 Robert Giesecke 的“UnmanagedExports”nuget 包创建一个 C# 非托管 DLL,但它似乎没有创建任何入口点。

完整代码在这里:

using System.IO;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;

namespace ImpactHive
{
    internal static class Main
    {
        [DllExport("_RVExtension@12", CallingConvention = CallingConvention.StdCall)]
        static void RVExtension(out char output, int outputSize, char function)
        {
            using (StreamWriter writer = new StreamWriter(@"C:\dll_log.txt"))
            {
                writer.WriteLine("It works!");
                writer.WriteLine(function);
            }

            output = function;
        }
    }
}

我做错了什么?

澄清:

这是一个extension DLL for Arma 3,它需要一个名为“_RVExtension@12”的入口点并带有签名:

void __stdcall RVExtension(char *output, int outputSize, const char *function);

编辑:我在项目设置中将目标平台指定为 x86,但没有运气。

【问题讨论】:

  • dumpbin /exports 显示了什么?
  • @HansPassant 忘了提一下,我已经将目标平台设置为 x86 并允许不安全代码,但它仍然不适合我。
  • @pm100,我在什么情况下运行它?我一直在使用nirsoft.net/utils/dll_export_viewer.html 来检查可用的入口点
  • dumpbin 是用于检查二进制文件的 ms 工具 - 在 sdk 中。我猜 nirsoft 也会这样做
  • 它做了类似的事情,但是 dumpbin 可以正常工作,而 nirsoft 没有在 .NET DLL 中显示入口点

标签: c# dll dllexport stdcall


【解决方案1】:

事实证明[DllExport] 属性完全按照预期工作。

我遇到的问题是 C# 中没有本机 [DllExport] 属性的原因之一——Dll 的调用者必须加载 .net 框架,以便 C# dll 显示入口点它。

问题是我用来检查暴露入口点的应用程序没有加载 .net 框架,因此没有报告入口点。

这已通过打开 VS2013 的开发人员命令提示符并运行 dumpbin /exports "C:\myDllName.dll" 得到确认,返回以下内容:

Dump of file C:\myDllName.dll

File Type: DLL

  Section contains the following exports for \myDllName.dll

    00000000 characteristics
    54F6EC86 time date stamp Wed Mar 04 11:29:10 2015
        0.00 version
           0 ordinal base
           1 number of functions
           1 number of names

    ordinal hint RVA      name

          0    0 000028CE _RVExtension@12

  Summary

        2000 .reloc
        2000 .rsrc
        2000 .sdata
        2000 .text

清楚地显示暴露的入口点...

这意味着我无法将此 dll 用于我的扩展,因为 Arma 3 游戏引擎默认不加载 .net 框架,因此无法调用我的 C# dll。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 2016-02-13
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多