Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting a native C function from a .net DLL? [duplicate]

I have a .net assembly written in C#, and I'm looking to export a native C function from the assembly.

I have an application which will perform a 'LoadLibrary()' on any DLL's found in a 'plugin' folder. After loading the DLL, the application performs a 'GetProcAddress' looking for a function named 'Register'. The application expects this function to follow the C calling convention.

How can I export a function named 'Register' from my .net assembly, so I can successfully hookup with the plugin system for this application?

Thanks, Andrew

like image 333
Andrew Avatar asked May 13 '11 14:05

Andrew


People also ask

What does __ Declspec Dllexport do?

The __declspec(dllexport) attribute exports the definition of a symbol through the dynamic symbol table when building DLL libraries.

How to export DLL C++?

You can export an entire C++ class by placing the __declspec(dllexport) before the class name, or you can export a single method by placing __declspec(dllexport) before the method name. Make class methods static and public. The C/C++ DLL Adapter does not allow you to call public non-static methods.

Which keyword can be used to disable name decoration when exporting a function from a DLL?

You can use the "-Wl,--kill-at" linker switch to disable name mangling.


2 Answers

Use this tool.

like image 123
SLaks Avatar answered Oct 09 '22 06:10

SLaks


Write a .Net library in Managed C++ and there you can export a "Native" method/function.

like image 40
vozzie Avatar answered Oct 09 '22 04:10

vozzie