Autor Beitrag
Der Jan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Mi 26.10.05 08:36 
Hallo,

ich versuche gerage eine DLL unter Delphi einzubinden, leider gibts kein interface und so bin ich dabei, selbst eins zu schreiben und dabei gibts ein Problem.
Im C-include steht z.B.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
int ITBAPI ITB_GetVersionInfo(int FAR *Major,
                              int FAR *Minor,
                              int FAR *Build,
                              int FAR *ExpDay,
                              int FAR *ExpMonth,
                              int FAR *ExpYear);


in Delphi schreibe ich so:

ausblenden 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:
function ITB_GetVersionInfo(Major, Minor, Build, ExpDay, ExpMonth, ExpYear: PInt): integer; external 'itbs20.dll';

// ...

procedure test;
var maj, min, build, d, m, y: integer;
    res: integer;
begin
    res := ITB_GetVersionInfo(@maj, @min, @build, @d, @m, @y);
    ShowMessage(IntToStr(res));
    // ...
end;

// oder alternativ

procedure test;
var maj, min, build, d, m, y: PInt;
    res: integer;
begin
    new(maj);
    new(min);
    new(build);
    new(d);
    new(m);
    new(y);
    res := ITB_GetVersionInfo(maj, min, build, d, m, y);
    ShowMessage(IntToStr(res));
    // ...
end;


Die Dll wird intialisiert und die Funktion aufgerufen (sehe ich daran, das die Trial-Version der DLL eine MessageBox anzeigt mit Infos) danach kommt eine Access Violation.
Kann ja eigentlich nur daran liegen, daß die Pointer, die ich übergeben falsch sind oder an dem FAR* .
Wer kann helfen?

_________________
Gruß, Jan
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mi 26.10.05 08:42 
Glaub ich eher weniger, FAR benötigt C (da sehr maschienennah) das es 4Bytes für den Pointer reservieren soll da es halt ein "weiter" Sprung ist von außerhalb des Programms.

Ist PInt ein eigener Typ? Probier es erst einmal mit ganz normalen Integer Variablen deren zeiger du mit @Variable auflöst.
Der Jan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Mi 26.10.05 08:47 
ausblenden Delphi-Quelltext
1:
type PInt = ^integer;					


Das mit @Variable hab ich schon probiert, siehe erste Variante im Delphi-Source...

_________________
Gruß, Jan
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mi 26.10.05 08:49 
Der Crash liegt wahrscheinlich dass der Delphi-Compiler standardmässig andere Funktions-Aufrufkonventionen hat als Windows verwendet. Wahrscheinlch musst du deine externe Funktion mit stdcall deklarieren. Dafür kannst du Pointer auf Integer in einer C-Funktionsdeklaration in Delphi auch als Variablenparameter übersetzen.

ausblenden Delphi-Quelltext
1:
function ITB_GetVersionInfo(var Major, Minor, Build, ExpDay, ExpMonth, ExpYear: Integer): Integer; stdcall; external 'itbs20.dll';					


Wenn es sich um eine reine C-Bibliothek handelt, kannst du es statt mit stdcall auch mit cdecl probieren, aber Standard für DLLs ist eigentlich stdcall.

Das FAR sagt gar nichts aus und wird von aktuellen C-Compilern ignoriert - einen Unterschied zwischen Near- und Far-Pointern gibt es nur unter 16-Bit Code (DOS und Windows bis 3.11, also echt antik).

Stefan
Der Jan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Mi 26.10.05 08:58 
"stdcall" funktioniert. Danke!

_________________
Gruß, Jan
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mi 26.10.05 11:50 
mist das habe ich doch tatsächlich übersehen :(
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Mi 26.10.05 12:04 
und anstatt die einzelnen pointer anzulegen
kannst du ach einfach:

ausblenden Delphi-Quelltext
1:
function ITB_GetVersionInfo(var Major, Minor, Build, ExpDay, ExpMonth, ExpYear: Integer): integer; external 'itbs20.dll'; stdcall;					


nehmen

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit