i have a simple task:
is it possible to write a Delphi DLL and put a .Net Assembly (with only one interface with 4 methods and one class implementing the interface) besides it and call it from the Delphi DLL?
I mean, can i import the .Net types directly from the .Net assembly (relative filename) if i create a tlb and a delphi unit for the tlb, without registering the Assembly/tlb?
best, thalm
EDIT (what i found):
Most solutions must register at least one dll/tlb for COM. But the most promising thing i found was: Unmanaged Exports from Robert Giesecke, its a Visual Studio project template which lets you write static C# (or whatever .Net language) methods and call them from any unmanaged language, awesome:
class Test
{
[DllExport("add", CallingConvention = CallingConvention.StdCall)]
public static int Add(int left, int right)
{
return left + right;
}
}
EDIT 2: It really works! You can even control the type marshalling, unbeliveable!!!
One little piece of advice: You do not have to make your exports public.
Your class is internal already, so it wouldn't show up when consumed from another assembly.
However, it is also perfectly fine to add an export to an existing static class, but declare it as private so that it doesn't show up when consumed from .Net. (unmanaged Exports tend to look a bit creepy)
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