Autor Beitrag
katjah
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win10 65bit
D7, D2005
BeitragVerfasst: Mo 21.08.06 11:44 
Ich habe Probleme mit der Verwendung von DLLs.
Beim statischen Einbinden funktioniert dasselbe problemlos. Sobald das ganze dynamisch eingebunden wird, gibt es Probleme:
entweder liefert die Funktion oder Müll zurück oder aber das ganze bricht mit einem Laufzeitfehler (mit Anzeige des CPU-Fensters) ab.
Das ganze scheint sich also irgendwas im Speicher zu zerdeppern.
Evtl. hat von Euch einer eine Idee, was ich da noch falsch mache ?

Hier der Code der dll:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
library TurnFkt;
 
uses
  SysUtils,
  Classes;

{$R *.res}

var ColCaption:string;

function GetColCaption(ColName,Spezial:PChar): PChar;stdcall;
begin
    ColCaption:=ColName;
  Result:=PChar(ColCaption);
end;

exports GetColCaption;

begin
end.


und hier die Funktion im aufrufenden Programm:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function GetColCaption(ColName,Spezial:PChar): PChar;stdcall;
//  external '../TurnFkt.dll';
type TGetColCaption=function(ColName,Spezial:PChar): pchar;
var FGetColCaption:TGetColCaption;
    Handle        : THandle;
begin
  Handle:=LoadLibrary(Pchar('../TurnFkt'));
  if Handle<>0 then
  begin
    @FGetColCaption:=GetProcAddress(Handle,'GetColCaption');
    if @FGetColCaption<>nil then
      Result:=FGetColCaption(ColName,Spezial);
    FreeLibrary(Handle);
  end;
end;


Als Anleitung habe ich das Dll-Tutorial von www.dsdt.info verwendet, Sharemem möchte ich nicht einsetzen.

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 24.08.2006 um 18:44

_________________
Gruß Katja
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 21.08.06 12:07 
du musst das "stdcall" hinter die "type TGetColCaption=" deklaration der dll-funktion setzen, nicht hinter die function-deklaration in deinem programm.

grüße
alex
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 21.08.06 12:11 
Moin!

Und hier muss das "@" weg:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
begin
  @FGetColCaption:=GetProcAddress(Handle,'GetColCaption');
  if (FGetColCaption <> NIL) then
    Result:=FGetColCaption(ColName,Spezial);

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
katjah Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win10 65bit
D7, D2005
BeitragVerfasst: Mo 21.08.06 13:15 
Zitat:
du musst das "stdcall" hinter die "type TGetColCaption=" deklaration der dll-funktion setzen, nicht hinter die function-deklaration in deinem programm.


Das hilft leider nichts.

Zitat:
Und hier muss das "@" weg:

das lässt der Compiler nicht durch.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 21.08.06 13:18 
Moin!

Hier ist ein Beispiel, wie man dynamisch DLLs linken kann (ganz unten im Quelltext). ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Mo 21.08.06 13:18 
user profile iconkatjah hat folgendes geschrieben:


ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function GetColCaption(ColName,Spezial:PChar): PChar;stdcall;
//  external '../TurnFkt.dll';
type TGetColCaption=function(ColName,Spezial:PChar): pchar;
var FGetColCaption:TGetColCaption;
    Handle        : THandle;
begin
  Handle:=LoadLibrary(Pchar('../TurnFkt.dll'));
  if Handle<>0 then
  begin
    @FGetColCaption:=GetProcAddress(Handle,'GetColCaption');
    if @FGetColCaption<>nil then
      Result:=FGetColCaption(ColName,Spezial);
    FreeLibrary(Handle);
  end;
end;



HTH Frank

_________________
EB FE (die wahrscheinlich kürzeste Endlosschleife der Welt :) )
BA 01 00 00 00 52 EB 09 BB 4D 11 86 7C FF D3 EB 0D E8 F2 FF FF FF 63 68 61 72 6D 61 70 00 C3
katjah Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win10 65bit
D7, D2005
BeitragVerfasst: Do 24.08.06 16:08 
Vielen Dank für die Hilfe, ich habe es inzwischen hinbekommen,
siehe www.delphipraxis.net...st599583.html#599583