C# Dll - export functions

10,453

Hey so actually I was doing it perfectly fine.

Weirdly Robert Giesecke's Unmanaged Exports ignores the first export??

So any exports I created below that one worked and was recognised.

I checked with CFF explorer to see the valid exports, and all but the first one was there. So I just left a blank export on top.

Share:
10,453
Zeller33
Author by

Zeller33

Updated on September 03, 2022

Comments

  • Zeller33
    Zeller33 over 1 year

    I am trying to create a c# dll with a few exportable functions. Then I want a C++/unmanaged program to load that .dll and call a particular exported function inside the dll.

    I'am using Robert Giesecke's Unmanaged Exports. But it doesn't seem to work.

    I ran the unmanaged program in a debugger and it successfully does "LoadLibrary()", but when it tries to "GetProcAddress(test_start)" the call fails and returns zero.

    This is my c# code:

        using System.Runtime.InteropServices;
        using RGiesecke.DllExport;
        using etc...; 
    
        namespace test_dll
        {
    
            public class Class1
             {  
    
                  [DllImport("kernel32.dll")]
                  public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
    
                  [DllExport("test_start", CallingConvention = CallingConvention.Cdecl)]
                  public static void test_start()
                  {
                        MessageBox.Show("It works","YES");
                  }
    
             }
        }
    

    The .dll builds fine and the CPU match (x86), but the unmanaged program can't get the export function address once the c# dll has been loaded.

    Its pretty basic right now, but I'm just trying to get it to work. I'll need the imports later on.

    Any help please, the documentation for the nuget package is quite thin. Thanks