Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 17.09.07 18:35 
wie kann ich einen string aus delphi an eine funktion übergeben?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure chaten();

begin
asm
  PUSH 'Ich liebe euch alle!!!'
  CALL 400456
end;
end


Ich muss nur nen Pointer auf nen Ascii string auf dem Stack haben

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Mo 17.09.07 20:46 
Delphi-Strings sind recht komplex. Prinzipiell kann man die zwar auch per ASM nachbauen(siehe hierzu: www.dsdt.info/inside...rna/ansistrings.php), aber das ist IMHO ungerechtfertigter Aufwand. Numm in dem Fall besser PChar. Das ist dann nix anderes als n Pointer auf n Speicherbereich, in dem die ASCII-Werte stehen. Ein #0 schließt den String ab...

Das müsste dann ungefähr so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
// Pseudocode:
s: string;
s2: PChar;
begin
  s := 'Das ist ein Test';
  s2 := PChar(s);
  asm
    push s2
  end;
end;


mfg

Christian

P.S.: bitte delphi-Tags verwenden...

_________________
Kaum macht man's richtig, schon klappts!
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Di 18.09.07 06:59 
jo ok danke
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: Di 18.09.07 20:21 
Alternativ kann man aber auch das machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure Foo;
asm
    PUSH OFFSET [@@StrVarPtr+8]
    CALL Bar
    JMP @@E

@@StrVarPtr:
    DD -1 //Reference Count: Constants have ALWAYS -1
    DD 12 // String Length, not including the 0 terminator
    DB 'Hello World!'0 //Actual String Data, The NULL Byte is recommended (and some Str-Routines really require it!
@@E:
end;


Das was ich hier in ASM gemacht hab, macht Delphi sonst hinter dem RET-Befehl der Prozedur. Da Delphi aber u.U. noch ein Stackframe erstellt, kann man oftmals schlecht direkt mit RET rausspringen. Außerdem würde man damit Toten Code im Binary erzeugen, was auf die Weise vermieden wird.

_________________
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.