Jonnie
Jonnie

Reputation: 51

Export managed function to unmanaged

I'm trying to export some of my functions using ( https://www.nuget.org/packages/UnmanagedExports ) but it doesn't seem to be working.

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()
        {
        }
    }
}

I am using DLL EXPLORER to view the exported functions and unfortunately, in my dll there is no exported function.

Upvotes: 2

Views: 612

Answers (1)

aybe
aybe

Reputation: 16662

Tried and verified here, it's working as expected :

  • Created a Class library project
  • Added the package from NuGet
  • Changed configuration to x86

Created a few functions :

using RGiesecke.DllExport;

namespace ClassLibrary1
{
    public static class Class1
    {
        [DllExport]
        public static int Hello()
        {
            return 1;
        }

        [DllExport]
        public static void Nope()
        {
        }
    }
}

As you can see the functions are exported correctly:

enter image description here

If in doubt, check the DLL with CFF Explorer, try on a new project.

NOTE: when you create another configuration of your project, the output is not in bin\Debug but in bin\x86\Debug, make sure you are checking the right DLL.

Upvotes: 2

Related Questions