Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Using a class in a C# DLL in delphi... ( Is that even possible?)

This thread is locked; no one can reply to it. rss feed Print
Using a class in a C# DLL in delphi... ( Is that even possible?)
Ariesnl
Member #2,902
November 2002
avatar

I have a DLL made for C# or C++
but since noone here(at work) is fluent in C++ I have to use Delphi.

If that DLL just worked with functions, there would not be a problem.. BUT...

All functions I need are in a certain class wich I need to instantiate first...

I doubt Delphi can handle a constructor in the C++ way ...

anyone with a smart idea ???

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Niunio
Member #1,975
March 2002
avatar

If you know the "internal name" of the method may be you can use (pseudo):

PROCEDURE CsharpProcedure (Object: POINTER); CDECL;
EXTERNAL 'shared_lib_name' NAME 'CsharpMangledName'; 

PROCEDURE PascalClass.Method;
BEGIN
  CsharpProcedure (SELF.CsharpObject);
END;

-----------------
Current projects: Allegro.pas | MinGRo

BAF
Member #2,981
December 2002
avatar

You can't pull a "C# dll" in because they aren't normal DLLs, it's all intermediate .NET code, IIRC. Same with managed c++ DLLs.

Ariesnl
Member #2,902
November 2002
avatar

The thing also uses namespaces.. there is no such thing in Delphi as far as I know..

I'd rather use C# or C++ .. but by boss is affraid I will be the only one who understands the code :-/

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Tobias Dammers
Member #2,604
August 2002
avatar

If the project you're working on is a Delphi one, sticking with Delphi is the sane thing to do.
In theory, C# can be compiled into native code, but when they say "C#", people typically mean "C# .NET", which means you need the .NET CLR to run the code.
If you can get your Delphi code to produce .NET IL assemblies, then you might be able to share code between them.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Kibiz0r
Member #6,203
September 2005
avatar

There's a .NET flavor of nearly every language. I bet you could use the Delphi implementation and it would work fine. But then you need the .NET Framework to run it, unless there's a way you can compile the Delphi.NET project natively and statically...?

BAF
Member #2,981
December 2002
avatar

If it was compiled natively, it wouldn't be .NET at that point. There is also no way around having the framework if you're interacting with other .NET assemblies.

Peter Hull
Member #1,136
March 2001

What you ask is possible but IMO you would add complication for little gain. If the rest of your company is using Delphi then stick to that.

Having said which, RAD Studio 2007 includes Delphi .NET (link), or there is a project called 'Delphi.NET' on Sourceforge (link)

You can call .NET assemblies from non-managed code (link. Your .NET classes get wrapped by COM objects. I think Delphi can work with COM objects, can't it?

Pete

Niunio
Member #1,975
March 2002
avatar

Peter Hull said:

I think Delphi can work with COM objects, can't it?

I used COM objects in Delphi 6 some years ago.

-----------------
Current projects: Allegro.pas | MinGRo

Tobias Dammers
Member #2,604
August 2002
avatar

I don't think the pain is going to be worth the gain.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Audric
Member #907
January 2001

If the class only serves as a namespace, you can write (still in C#) static functions that wrap each method you need: instanciate the object, call method, release object. It should be much easier to call such static methods from Delphi.

Go to: