Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Call Delphi DLL from .NET Application


This question is answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Oct 14, 2017 9:18 AM Last Post By: Rudy Velthuis (...
ram sailesh

Posts: 2
Registered: 11/12/17
Call Delphi DLL from .NET Application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 7:43 AM
I've Delphi 5 based Library

I would like to call that Library in C#/.NET without using COM way (registering the DLL and call it from >NET)

I upgraded Delphi 5 library to Delphi Tokyo

I've read articles that Delphi for .NET is deprecated from XE 4 onwards.
http://www.itwriting.com/blog/7338-no-more-delphi-for-net-prism-removed-from-rad-studio-xe4.html

I would like to know is it possible to call functions and classes of Delphi DLL natively in C#?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Call Delphi DLL from .NET Application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 10:27 AM   in response to: ram sailesh in response to: ram sailesh
ram sailesh wrote:

I would like to call that Library in C#/.NET without using COM way
(registering the DLL and call it from >NET)

It is possible, via PInvoke, but only if:

- the library is compiled as a DLL.

- its exported functions are written to follow C standards, which means
using interop-safe data types and calling conventions.

Otherwise, you are out of luck, you will have to create a C#/.NET
compatible wrapper for the library.

I upgraded Delphi 5 library to Delphi Tokyo

I've read articles that Delphi for .NET is deprecated from XE 4
onwards.

That doesn't apply in this situation. But yes, Delphi.NET no longer
exists.

I would like to know is it possible to call functions and classes of
Delphi DLL natively in C#?

Functions, yes. Classes, no.

--
Remy Lebeau (TeamB)
ram sailesh

Posts: 2
Registered: 11/12/17
Re: Call Delphi DLL from .NET Application  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 12, 2017 8:00 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for the information

using PInvoke is not an option for us as PInvoke is similar to invoking Delphi Code via COM except with even more restrictions on classes.

I didn't quite understand why Delphi .NET wont be of use here

http://edn.embarcadero.com/article/28972

If i compile Delphi using DCCIL i will get assembly that can be run using .NET runtime right?

Remy Lebeau (TeamB) wrote:
ram sailesh wrote:

I would like to call that Library in C#/.NET without using COM way
(registering the DLL and call it from >NET)

It is possible, via PInvoke, but only if:

- the library is compiled as a DLL.

- its exported functions are written to follow C standards, which means
using interop-safe data types and calling conventions.

Otherwise, you are out of luck, you will have to create a C#/.NET
compatible wrapper for the library.

I upgraded Delphi 5 library to Delphi Tokyo

I've read articles that Delphi for .NET is deprecated from XE 4
onwards.

That doesn't apply in this situation. But yes, Delphi.NET no longer
exists.

I would like to know is it possible to call functions and classes of
Delphi DLL natively in C#?

Functions, yes. Classes, no.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Call Delphi DLL from .NET Application
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2017 11:32 AM   in response to: ram sailesh in response to: ram sailesh
ram sailesh wrote:

using PInvoke is not an option for us

Sorry, but PInvoke is the ONLY way to use a Delphi native DLL
directly in C#. The other options are to re-write the Delphi code to
use ActiveX/COM, or wrap the DLL inside a C++/CLI assembly that uses
native code internally (but then you have to manually replicate the
kind of marshalling that PInvoke would have done for you automatically).

as PInvoke is similar to invoking Delphi Code via COM

No, it is not, not even close.

except with even more restrictions on classes.

You can't access Delphi classes in C# at all.

I didn't quite understand why Delphi .NET wont be of use here

Because

1. it doesn't exist anymore. It was discontinued years ago.

2. it compiles to .NET assembly code, not native code. You would have
to port your existing DLL code to .NET code. But then, the DLL won't
be a native library anymore, so you wouldn't be able to use it in
Delphi if needed, unless you use something like AToZed CrossTalk or
similar framework.


That article is 15 years old

If i compile Delphi using DCCIL i will get assembly that can be run
using .NET runtime right?

Technically, yes.

--
Remy Lebeau (TeamB)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: Call Delphi DLL from .NET Application
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 14, 2017 9:18 AM   in response to: ram sailesh in response to: ram sailesh
ram sailesh wrote:

I've Delphi 5 based Library

I would like to call that Library in C#/.NET without using COM way
(registering the DLL and call it from >NET)

I upgraded Delphi 5 library to Delphi Tokyo

I've read articles that Delphi for .NET is deprecated from XE 4
onwards.

The last version that compiles Delphi for .NET (and the VCL for .NET)
is version 2007. It is the only (AFAIK) version that supports .NET 2.0
while previous versions supported 1.3x.

--
Rudy Velthuis http://www.rvelthuis.de

"Theology is never any help; it is searching in a dark cellar
at midnight for a black cat that isn't there. Theologians can
persuade themselves of anything."
-- Robert Heinlein
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02