Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a C# DLL That Can Be Imported in a Delphi App Using stdcall - Possible?

I have a program that I need to create a DLL for, hopefully in C#. The program is written in Delphi and I have an interface file to code to. The interface uses the stdcall calling convention.

Is it possible to create a C# DLL that conforms to the interface and can be used in the Delphi application?

Is there some sample code that demonstrates how to code the C# DLL to a stdcall interface method?

like image 435
Dave Avatar asked Jun 30 '09 11:06

Dave


People also ask

Can I have 2 Gmail accounts?

Can I Have Multiple Gmail Accounts? The short answer is, "Yes, you can have multiple Gmail accounts." Many professionals have both a personal Gmail account and a work Gmail account tethered to their CRM.


2 Answers

This is not possible in pure C#, but this is an article that shows how to add an unmanaged export table to your C# library, which can then be used in any other language. Note that the hordes of references to Blitz should not put you off - they relate to the author's own context and have nothing to do with the basic concept and how it works.

There is also a section in Brian Long's one conference paper. In a twist that you could see as somewhat ironic, Delphi.Net actually supported unmanaged exports directly despite C# not doing so. I have no idea if this is true of Delphi Prism as well.

like image 80
Cobus Kruger Avatar answered Nov 06 '22 08:11

Cobus Kruger


I have been down this road before. The solution I picked was to create a NEW C# assembly (I later ported this to Prism) which exposed via com interop the functionality I needed to reach. I was finding by black boxing the API calls into something simpler, I was able to reduce the number of classes I had to deal with across the interop barrier.

I did look at Hydra, but it was overkill for what I was trying to do... which was access a 3rd party SDK which was presented in .net assemblies to process data. If you are looking at embedding the functionality (gui objects, ect) in your application then you should give Hydra some consideration.

I did use Managed.VCL for a very early version of the system, but later abandoned it for the Prism/C# com interop approach which was simpler to deploy, and more stable.

like image 44
skamradt Avatar answered Nov 06 '22 09:11

skamradt