Exporting dll functions to unmanaged programs
Asked Answered
I

1

4

How can I export my c# dll functions to be able to use them from unmanaged programs.

  • For example : Dll in c# and the application in Delphi/c++ .

I don't have the source of the exe because is not Open S. Can't use COM.

Ileneileo answered 28/9, 2012 at 21:42 Comment(1)
Had some problems with that Nuget and found quite easy way #225777Rinaldo
W
9

I recommend using Robert Giesecke's Unmanaged Exports.

Whittle answered 28/9, 2012 at 21:48 Comment(8)
I'm constantly amused that this question gets asked repeatedly and always gets a different answer :\Markley
@Michael It always gets the same answer from me.Whittle
The problem is this gets asked so often that the same people rarely see it: #2812838, #225777, #10821609, #1636179Markley
Your answer, BTW, is easily the "best"; maybe you should go add it to the rest of the list :)Markley
Still waiting for an answer that explains how it works. Without that, you'll never know when it stops working or how expensive it is. Those stubs certainly are not cheap. Giesecke prefers to be mysterious, more fun that way.Parmesan
@HansPassant: You have have found out in the over 2 years since that comment, but if not, It works using the the frameworks reverse P/Invoke support. (This makes your assembly platform-specific.) Basically in IL you can add .export [1] to a method to export a method in slot one of the unmanaged export table. A marshaling thunk gets generated at runtime. Use the normal marshaling attributes like you would with forward P/Invoke to customize the effective native signature. The .export clause also takes an optional 'as exported_name' clause to allow you to set the name in the export table.Notation
@HansPassant: (Continued). Chapter 18 of "Expert .NET 2.0 IL Assembler" describes this is slightly more detail, although I suspect better books exist.Notation
Sure, I just use C++/CLI to accomplish the exact same thing. It just takes __declspec(dllexport). I can set a breakpoint on it.Parmesan

© 2022 - 2024 — McMap. All rights reserved.