Autor Beitrag
Holg_i
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Do 18.08.11 17:35 
in C habe ich folgenden Code:

ausblenden C#-Quelltext
1:
2:
3:
4:
  int MyResult
  int MyArray[31];

  MyResult = DLL_Abfrage(myArray);


das geht auch echt fein. In VB:

ausblenden Quelltext
1:
2:
3:
4:
  Dim MyResult As Long   
  Dim MyArray(0 to 31) As Long

MyResult = DLL_Abfrage(MyArray(0))


geht auch

ABER

ausblenden Delphi-Quelltext
1:
2:
3:
4:
MyArray: Array[0..31of LongInt;
MyResult: LongInt;

MyResult = DLL_Abfrage(MyArray[0]);


bringt Laufzeitfehler.

Was mache ich falsch???


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 18.08.2011 um 18:52
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 18.08.11 18:00 
Punkt 1: Dein VB-Code deklariert ein Array, was einen Eintrag. Zu gross ist.

Zudem: Wie bindest du die Funktion jeweils ein? Wie ist sie im Original deklariert?

Denn ohne die Deklaration kann man da recht wenig sagen.

Ach ja: Don't ever use int for anything that should work!

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Delphi-Laie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1600
Erhaltene Danke: 232


Delphi 2 - RAD-Studio 10.1 Berlin
BeitragVerfasst: Do 18.08.11 19:24 
user profile iconHolg_i hat folgendes geschrieben Zum zitierten Posting springen:
Was mache ich falsch???


Den Delphi-Quelltext hier zurückzuhalten.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 18.08.11 21:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
MyArray: Array[0..31of LongInt;
MyResult: LongInt;

MyResult = DLL_Abfrage(MyArray[0]);


Ist das in der letzten zeile absichtlich eine Abfrage oder sollte das eine Zuweisung sein? Ich schieß mal so ins Blaue aber kanns sein das der vl nur nen Pointer aufs Array haben mag? Weil in C is ja n Array eig. nur Pointergeballere, was ich mich so an meine wenigen Stunden C erinnern kann.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Do 18.08.11 22:35 
Ausserdem aufpassen in Delphi mit dem Speicher des Arrays, soalnge Du die RTLXXX.BPL nicht dynamisch einbindest, nutzen Hauptprogramm und DLL unterschiedliche Speichermanager.

Ausserdem musst/willst Du sicherlich das Array als Pointer übergeben, ich glaub, das geht eher so:

ausblenden Delphi-Quelltext
1:
MyResult = DLL_Abfrage(@MyArray[0]);					


Ist allerdings sehr abhängig von der Deklaration in der DLL. Ausserdem mal schaun, dass beides gleich als cdecl oder so registriert ist.

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
Holg_i Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Fr 19.08.11 08:54 
Nun so noch mal den ganzen Code

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
Private Declare Function DLL_Abfrage Lib "jetr.dll" Alias "FillA" (Inhalt As Long) As Long
Private Sub testBtn_Click()
Dim retValue As Long
Dim MyArray(0 To 31) As Long
retValue = DLL_Abfrage(MyArray(0))
End Sub


Das geht im Array steht das was die DLL übergibt. In Delphi:

ausblenden volle Höhe 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:
unit Haupt;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
  private
    DLL_Abfrage: function(Inhalt: LongInt): LongInt; stdcall;
    { Private-Deklarationen }
  public
    handelDLL: HINST;
    { Public-Deklarationen }
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
// DLL Einbinden
     handelDLL:=0;
     handelDLL := LoadLibrary('jetr.dll');
     if handelDLL = 0 then // DLL konte nicht geladen werden Fehlermeldung und Programmabbruch
     begin
          MessageBox(0,'DLL Ladefehler','ERROR',MB_OK or MB_ICONSTOP);
          Application.Terminate;
     end
     else
     begin
          DLL_Abfrage:= GetProcAddress(handelDLL,'FillA');
     end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    FreeLibrary(handelDLL);
end;
procedure TForm1.Button1Click(Sender: TObject);
var MyArray: Array[0..31of LongInt;
    retValue: LongInt;
begin
     retValue:= DLL_Abfrage(MyArray[0]);  
end;
end.


Geht das nicht. Ich verstehe das einfach nicht.
Holg_i Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Fr 19.08.11 10:57 
Danke ich habe es hinbekommen:


ausblenden Delphi-Quelltext
1:
DLL_Abfrage: function(Inhalt: LongInt): LongInt; stdcall;					

muss

ausblenden Delphi-Quelltext
1:
DLL_Abfrage: function(Inhalt: Pointer): LongInt; stdcall;					

sein. Die Abfrage muss

ausblenden Delphi-Quelltext
1:
retValue:= DLL_Abfrage(@MyArray);					

sein und nicht

ausblenden Delphi-Quelltext
1:
retValue:= DLL_Abfrage(MyArray[0]);