Autor Beitrag
ebber
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Do 09.10.08 16:52 
Hallo,

ich war mir nicht so sicher, aber ich glaube das passt mehr ins Delphi Forum wie ins C#.
Ich habe eine Dll in Delphi und habe darin ein Event von einer Komponente. Wie genau muss ich das jetzt deklarieren oder sowas um von meinem C# Programm(oder überhaupt von außen) Zugriff darauf zu bekommen? Geht das überhaupt?

MfG
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Mo 13.10.08 16:07 
Hallo,

ich denke der erste Schritt heist erst einmal Callback-Funktion. Hier findest du ein kleines Beispiel: www.delphi-forum.de/viewtopic.php?p=386566

Vom Prinziep läuft es so, du übergibst deiner DLL "zur Initialisierung" die Adresse der Funktion aus deinem Programm, welche bei dem Event ausgelöst werden soll. In deiner DLL schreibst du einen Eventhandler und vernüpfst ihn mit dem entsprechenden Ereigniss. Dieser macht dann nichts anderes als die Funktion, welche an der ihr bekannten Adresse liegt auf zu rufen.

Wie dass dann aus C# funktioniert ist eine Frage für das C#-Forum ;).

Gruß
Klabautermann
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Do 16.10.08 14:22 
Ok, scheint mir genau das zu sein was ich brauche. Danke.

Wenn ich nicht rausfinde wie das in C# funktioniert werde ich dort wohl mal Fragen.

MfG
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Sa 25.10.08 18:22 
Hallo,

ich dachte ich sollte nochmal schreiben wie das jetzt funktioniert:

Delphi Dll Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
TCallBack = procedure (count : integer); stdcall;

CallMainApp : TCallBack;

procedure onEvent();
begin
  CallMainApp(5);
end;

function SetCallback(CallBackFunction: TCallBack): Boolean; stdcall;
begin
      if Assigned(CallBackFunction) then
      begin
        CallMainApp := CallBackFunction;
        result := true;
      end
      else
        result := false;

end;


C# Programm Code:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
        [DllImport("Cappi.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void SetCallback(MulticastDelegate callback);

        public delegate void CallbackDelegate(int count);


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            CallbackDelegate del = new CallbackDelegate(Callback);
            SetCallback(del);
        }


        private static void Callback(int count)
        {
            Console.WriteLine("Param from Callback :" + count);
        }



Ich hoffe es hilft jemand.

MfG