Autor Beitrag
UliTs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP*, Win 7
xBase++, Delphi 10.3
BeitragVerfasst: Mo 17.01.11 14:14 
Hallo,

ich möchte eine DLL, die in C-Sharp geschrieben ist, in ein Delphi-Programm einbinden.
Als Test wurde mir eine C-Sharp DLL mit folgendem Quellcode zur Verfügung gestellt:
namespace test
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
{
  public class MyClass
  {
    /// Statische Methode. Addiert zwei Zahlen. 
    public static int addiere (int a, int b)
    {
      return a + b;
    }
    
    /// Addiert zwei Zahlen. 
    public int add(int a, int b)
    {
      return a+b;
    }
  }
}

Wie kann ich z.B. auf die Methode addiere zugreifen?
Uli


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Mo 17.01.2011 um 13:34
LSanchez
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 8



BeitragVerfasst: Mo 17.01.11 14:34 
Hallo Uli,

das .NET Framework unterstützt COM-Clients dabei, .NET-Komponenten zu benutzen.

Beispiel: www.computerleben.ne...e_schreiben-308.html


Gruß

Luis Sanchez
UliTs Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP*, Win 7
xBase++, Delphi 10.3
BeitragVerfasst: Mo 17.01.11 17:14 
Hallo Luis,

vielen Dank für die schnelle Antwort!
dein Link beschreibt das Ganze um von Visual Basic Script aus auf eine C# DLL zuzugreifen (C# = C++?).

Ich vermute, dies wird dann unter Delphi auch mit Hilfe einer CLSId und Component Object Modell - Klassen funktionieren?
Das heißt, ich benötige von der C-Sharp-DLL eine CLSId und die DLL muss unter Windows registriert werden?

Uli
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: Mo 07.03.11 23:53 
Falls das Thema noch aktuell ist, würde ich einfach mal (wie in letzter Zeit öfters) meine Lösung zu dem Problem anbieten

Was man damit kann, ist funktionen aus C# zu exportieren wie man es aus nativen Sprachen wie Delphi kennt.

Wenn das Projekt einmal mit dem Build Task ausgerüstet ist, geht einfach das hier:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
  public class MyClass
  {
    /// Statische Methode. Addiert zwei Zahlen.
    [DllExport] 
    public static int addiere (int a, int b)
    {
      return a + b;
    }
    
    /// Addiert zwei Zahlen. 
    public int add(int a, int b)
    {
      return a+b;
    }
  }


Und in Delphi einfach das hier:
ausblenden Delphi-Quelltext
1:
2:
  function Addiere(a, b : Integer) : Integer; stdcall
    extern 'DeineCSharpLibrary' name 'addiere';