Nyger
Nyger

Reputation: 215

Reading method from c# dll

I have compiled the following code to the assembly file test.dll:

namespace dll_test
{
    public class Class1
    {
        public int DoMagic()
        {
            return 12;
        }
    }
}

I'd like check my dll using DLL Export Viewer but when I did I don't see any function.

enter image description here

So where is the problem?

Upvotes: 1

Views: 293

Answers (1)

Fruchtzwerg
Fruchtzwerg

Reputation: 11389

You have to add your function to the dll-export table. In this table are the names of all functions you are possible to use in an executable. To do this in C# you have to add the Unmanaged Exports (DllExport for .Net) (https://www.nuget.org/packages/UnmanagedExports).

Then add the DllExport in a static method like this:

[DllExport("DoMagic", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
public static int DoMagic()
{
  return 12;
}

you find more information on https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports#TOC-C-: or the msdn: https://msdn.microsoft.com/en-us/library/z4zxe9k8.aspx

Upvotes: 2

Related Questions