Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I rather use a native dll or com server to call Delphi code from C#?

We are on the verge of writing a C# web service that will expose functionality contained in a native Delphi GUI app. Why would I choose to wrap the Delphi code in a native dll and why would I want to wrap it in a COM server? In other words: what factors do I need to consider when choosing one over the other? I am interested in factors with regard to coding, debugging, (automated) testing, deployment (installation at customers) and performance (overhead?).

like image 334
Marjan Venema Avatar asked Aug 21 '13 08:08

Marjan Venema


1 Answers

COM adds some significant advantages over a plain DLL:

  • Support for OOP (classes, interfaces)
  • Automatic memory management for strings (BSTR), arrays and objects (via interfaces)
  • No need to use platform invoke on the .NET side

So I would go for COM.

To use a Delphi class in .NET using a DLL you have to flatten the class on the Delphi side and rewrap it on the .NET side, which is kind of ugly.

A lot of Rudy's article on Delphi and C++ code applies to C# as well:

http://rvelthuis.de/articles/articles-cppobjs.html

like image 188
Jens Mühlenhoff Avatar answered Sep 24 '22 04:09

Jens Mühlenhoff