简体   繁体   English

DllExport没有创建入口点

[英]DllExport not creating an entry point

I am trying to create a C# unmanaged DLL using Robert Giesecke's " UnmanagedExports " nuget package, but it doesn't seem to be creating any entry points. 我正在尝试使用Robert Giesecke的“ UnmanagedExports ” nuget包创建一个C#非托管DLL,但它似乎并未创建任何入口点。

Full code here: 完整代码在这里:

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;
        }
    }
}

What am I doing wrong? 我究竟做错了什么?

Clarification: 澄清:

This is an extension DLL for Arma 3 which requires an entry point with the name of " _RVExtension@12 " with the signature: 这是Arma 3扩展DLL,它需要一个名称为“ _RVExtension@12 ”且带有签名的入口点:

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

Edit: I have specified the Target Platform as x86 in the project settings, with no luck. 编辑:我已经在项目设置中将目标平台指定为x86,没有运气。

It turns out the [DllExport] attribute was working exactly as intended. 事实证明[DllExport]属性完全按预期运行。

The problem I was having is one of the reasons why there isn't a native [DllExport] attribute in C# -- the Dll's caller must have the .net framework loaded in order for the C# dll to show the entry point to it. 我遇到的问题是C#中没有本地[DllExport]属性的原因之一[DllExport]的调用者必须加载.net框架,C#dll才能显示它的入口点。

The problem was that the app I was using to check the exposed entry points didn't load the .net framework, and therefore did not report the entry point. 问题是我用来检查暴露的入口点的应用程序没有加载.net框架,因此没有报告入口点。

This was confirmed by opening the Developer Command Prompt for VS2013 and running dumpbin /exports "C:\\myDllName.dll" which returned the following: 这是通过打开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

Clearly showing the exposed entry point... 清楚显示暴露的入口点...

This means that I am unable to use this dll for my extension as the Arma 3 game engine does not load the .net framework by default and therefore is unable to call my C# dll. 这意味着我无法使用此dll作为我的扩展名,因为Arma 3游戏引擎默认情况下不会加载.net框架,因此无法调用我的C#dll。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM