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#.
C code export provides an option to generate C code for a selected subsystem within a schematic model.
C++'s export keyword was originally meant to permit the separation of the definition of a template from its usages. It proved to be incredibly difficult to implement, and the “ export templates” C++ feature was dropped in C++11, having never seen widespread usage.
__declspec(dllexport) adds the export directive to the object file so you do not need to use a . def file. This convenience is most apparent when trying to export decorated C++ function names.
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 withMarshalAsAttribute
.During compilation, my task will modify the IL to add the required exports...
I've seen people do this before, but it required ildasm, adding the MSIL .export
directive, and then reassembling. A program named dll_tool
can do these steps for you.
If you want to build a mixed-mode DLL with both native and managed exports, you should be using C++/CLI, which is specially designed for this purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With