Entwickler-Ecke

Dateizugriff - Stack Overflow bei DLL


Progwriter - So 11.07.04 17:30
Titel: Stack Overflow bei DLL
Ich habe mir gerade ein Tutorial bezüglich DLL durchgelesen, danach habe ich mein derzeitiges Projekt so umgeschrieben, dass die Funktionen in eine DLL ausgelagert sind, und diese werden zur Laufzeit eingebunden.
Das Programm hat vorher gefunkt, doch jetzt kommt wenn ich Berechnungen (ist ein Programm zu Berechnungen in quadratischen Pyramiden) ausführen will, immer die Fehlermeldung, es sei ein Stack Overflow aufgetreten.
Kann mir jemand sagen, warum das so ist, beziehungsweise wie ich das Problem beheben kann?
Danke


raziel - So 11.07.04 17:43

Da hast Du doch sicher auch ein bisschen Code für uns, oder? ;-)

raziel


Progwriter - So 11.07.04 17:51

Ja bitte sehr:
das is meine DLL

Delphi-Quelltext
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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
library Vektor;


uses
  SysUtils,
  Classes;

{$R *.res}

type Tvektor = record
              x: real;
              y: real;
              z: real;
  end;

  function VektorSubtraktion(a, b: Tvektor):Tvektor; stdcall;
begin
  with result do Begin
    x := a.x - b.x;
    y := a.y - b.y;
    z := a.z - b.z;
  End;
end;


function VektorAddition(a, b: Tvektor):Tvektor; stdcall;
begin
  with result do Begin
    x := a.x + b.x;
    y := a.y + b.y;
    z := a.z + b.z;
  End;
end;

function VektorDivision2(a, b: Tvektor):Tvektor; stdcall;
begin
  with result do Begin
    x := a.x / b.x;
    y := a.y / b.y;
    z := a.z / b.z;
  End;
end;

function SMultiplikation(t: real; a: Tvektor):Tvektor; stdcall;
begin
  with result do Begin
    x :=t*a.x;
    y :=t*a.y;
    z :=t*a.z;
  End;
end;

function VektorDivision(t: real; a: Tvektor):Tvektor; stdcall;
begin
  with result do Begin
    x :=a.x/t;
    y :=a.y/t;
    z :=a.z/t;
  End;
end;

function Vektor1(x, y, z: real): Tvektor;  stdcall;
begin
  result.x := x;
  result.y := y;
  result.z := z;
end;

function Punktxyz(wert:String):TVektor;  stdcall;
var
r, x, y, z: string;
a:Integer;
begin
  r:=Copy(wert,2,Length(wert)-2);
  a:=Pos(',',r);
  x:=Copy(r,1,a-1);
  y:=Copy(r,a+1,Length(r));
  a:=Pos(',',y);
  z:=Copy(y,a+1,Length(y));
  y:=Copy(y,1,a-1);
  result:=Vektor1(Strtofloat(x),Strtofloat(y),Strtofloat(z));
end;

function Umfang(a,b:TVektor):Real;stdcall;
begin
Result:=4*(SQRT((b.x-a.x)*(b.x-a.x) + (b.y-a.y)*(b.y-a.y) + (b.z-a.z)*(b.z-a.z)));
end;

function Cross(a, b: TVektor): TVektor;  stdcall;
begin
   with result do begin
    x:=a.y * b.z-a.z * b.y;
    y:=a.z * b.x-a.x * b.z;
    z:=a.x * b.y-a.y * b.x;
   end;
end;

 function VektorBetrag(a:TVektor):Real;  stdcall;
 begin
  Result:=SQRT(SQR(a.x)+SQR(a.y)+SQR(a.z));
 end;

 function EinheitsNormalVektor(a:TVektor):TVektor;stdcall;
 begin
 Result:=VektorDivision2(a,a); // möglicher Fehler, da noch nicht a/|a|!!!
 end;

 exports
    EinheitsNormalVektor,
    VektorBetrag,
    Cross,
    Umfang,
    Punktxyz,
    VektorAddition,
    VektorDivision,
    VektorDivision2,
    SMultiplikation,
    Vektor1,
    VektorSubtraktion;
begin
end.


und nach dem Schema habe ich jede Funktion eingebunden:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
 type
  TVektorAllgemein=function(x,y,z: Real): TVektor; stdcall;
  function Vektor1(x,y,z: Real): TVektor;stdcall;

function Vektor1(x,y,z: Real): TVektor;
var VektorAllgemein:TVektorAllgemein;
    Handle:THandle;
begin
  Handle:=LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'Vektor.dll'));
  if Handle <> 0 then begin
    @VektorAllgemein := GetProcAddress(Handle, 'Vektor1');
    if @VektorAllgemein <> nil then begin
      result:=Vektor1(x,y,z);
    end;
    FreeLibrary(Handle);
  end;
end;


Und daraus resultiert ein Stack Overflow!


Moderiert von user profile icontommie-lie: Code- durch Delphi-Tags ersetzt.


raziel - So 11.07.04 17:55

Ich glaub jetz zwar nich ganz, dass des damit zusammenhängt, aber des is das einzige was ich grad seh:
Versuch mal die function "Vektor1" in deinem Hauptprogramm umzubenennen, evtl gibts da nen Konflikt.

raziel

//edit: Wahrscheinlich liegts am stdcall in der Deklaration von der function Vektor1 im Hauptprogramm. Entweder da wegmachen oder bei der implementation eins hinzufügen.


Progwriter - So 11.07.04 18:06

weder noch, hab das stdcall weggegeben und die function umbenannt, und es kommt noch immer zum Überlauf :cry:


Progwriter - So 11.07.04 19:23

Hat niemand eine Ahnung, wieso es zu einem Stack Überlauf kommt? wäre auch echt dankbar