Hallo,
ich binde eine dll mit Hilfe von ShareMem zur übergabe von Strings ein...
Das Programm funzt super, doch wenn ich es hinterher beende kommt immer ein Runtime Error...(aus dem ich nicht mehr ohne weiteres rauskomme)
woran kann das liegen?
Ein Beispielcode hier, hab nur ein bischen rumgespielt, deswegen bitte nicht über die Sinnigkeit diskutieren!
Dll:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
| library Project1;
uses ShareMem, SysUtils, Classes, Unit1 in 'Unit1.pas' ;
function addiere(zahl1, zahl2: integer): integer; stdcall; begin result:=zahl1+zahl2; end;
procedure meldung; stdcall; begin Form1 := TForm1.Create(nil); Form1.Label1.Caption := 'hallo'; Form1.ShowModal; end;
function geturl(url : string): string ; stdcall; begin Form1 := TForm1.Create(nil); Form1.Memo1.Text := url; result := Form1.Memo1.Text;
end;
exports addiere; exports meldung; exports geturl;
begin end. |
Anwendung:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
| unit Unit2;
interface
uses ShareMem, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private public
end;
var Form1: TForm1;
implementation
{$R *.DFM}
function addiere(zahl1, zahl2: integer): integer; stdcall; external 'project1.dll'; procedure meldung; stdcall; external 'project1.dll'; function geturl(url: string): string; stdcall; external 'project1.dll';
procedure TForm1.Button1Click(Sender: TObject); var x :integer ; begin x:=addiere(12, 3); Edit1.Text := inttostr(x); end;
procedure TForm1.Button2Click(Sender: TObject); begin meldung; end;
procedure TForm1.Button3Click(Sender: TObject); begin ShowMessage(geturl(Edit1.Text));
end;
end. |