Search code examples
c#c++notepad++dllexport

Is is possible to export functions from a C# DLL like in VS C++?


In VS C/C++ you could use extern "C" __declspec(dllexport) -function declaration-.

How do I accomplish this in a C# dll? Is there C# code equivalent to the above code?

Edit: More info

I am trying to create an add in for Notepad++ and I want to use C#, but the common way I've seen so far is to use legacy C++ code with the above call to export a few of the functions that Notepad++ expects to import and call. There is an example app using C#, but this still requires a loader DLL, which I assume from the comments/answers below is the only way for C#.


Solution

  • Unmanaged Exports => https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports

    DLLExport => https://github.com/3F/DllExport

    How does it work?

    Create a new classlibrary or proceed with an existing one. Then add the UnmanagedExports Nuget package.

    This is pretty much all setup that is required.

    Now you can write any kind of static method, decorate it with [DllExport] and use it from native code.
    It works just like DllImport, so you can customize the marshalling of parameters/result with MarshalAsAttribute.

    During compilation, my task will modify the IL to add the required exports...