2

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.

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:

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.

5
  • what did dumpbin /exports show?
    – pm100
    Mar 3, 2015 at 22:54
  • @HansPassant Forgot to mention, I've already set the Target Platform to x86 and Allowed Unsafe code but it's still not working for me. Mar 3, 2015 at 23:04
  • @pm100, in what context do I run this? I've been using nirsoft.net/utils/dll_export_viewer.html to check the available entry points Mar 3, 2015 at 23:04
  • dumpbin is the ms tool for inspecting binaries - in the sdk. I guess nirsoft does the same
    – pm100
    Mar 4, 2015 at 17:45
  • It does something similar, but dumpbin works properly whereas the nirsoft one doesn't show entry points in .NET DLLs Mar 4, 2015 at 22:14

1 Answer 1

2

It turns out the [DllExport] attribute was working exactly as intended.

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.

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.

This was confirmed by opening the Developer Command Prompt for VS2013 and running dumpbin /exports "C:\myDllName.dll" which returned the following:

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.