Autor Beitrag
OlafSt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 486
Erhaltene Danke: 99

Win7, Win81, Win10
Tokyo, VS2017
BeitragVerfasst: Mo 10.10.11 12:20 
Freunde, ich hab einen totalen Blackout :( Leider habe ich auch keine Kollegen mehr, die ich fragen könnte (bin der einzige Delphi-Entwickler weit und breit hier). Ich habe eine DLL vorliegen, die in C geschrieben ist und möchte die nun in Delphi einbinden.

Folgende Funktion wird exportiert:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
char  _stdcall GetData (
                             unsigned short ID,
                             unsigned char * Dest,
                             unsigned char * Source,
                             unsigned short CommandLen,
                             unsigned char * Command,
                             unsigned short * ResponseLen,
                             unsigned char * Response
                             );


Meine Delphi-Übersetzung (Delphi 2010):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function GetData(ID: Word; 
                 Dest: PByte; 
                 Source: PByte; 
                 CommandLen: Word; 
                 Command: PAnsiChar; 
                 ResponseLen: PWord; 
                 Response: PAnsiChar): shortint; stdcall;


Dest und Source sind einfache Bytes, aber die DLL will hier unbedingt Pointer, ergo PByte.

In ResponseLen übergibt man die maximale Größe des Buffers "Response" (max. 1000 Bytes), die Funktion liefert in ResponseLen dann auch zurück, wieviele Bytes in Response tatsächlich stehen.
Alle Zeichenketten sind korrekt als AnsiStrings deklariert, Unicode-Probleme sind in dieser Hinsicht keine vorhanden und es gibt auch keine Unicode-Version dieser DLL (wird es auch nie geben).

Ist meine Übersetzung soweit korrekt ?

Sorry, das ich euch mit so simplem Kram nerven muß :(


Moderiert von user profile iconNarses: Topic aus Windows API verschoben am Mo 10.10.2011 um 14:01

_________________
Lies, was da steht. Denk dann drüber nach. Dann erst fragen.
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: Mo 10.10.11 15:46 
Mach mal var ResponseLen: Word; aus dem vorletzten Parameter. Ist das Gleiche, aber du brauchst dich nicht selber um den Zeiger kümmern. Außerde ist der Rückgabetyp Byte, nicht Short.

Für Source und Dest würde ich PChar vorschlagen, was für Puffer übliches ist. Genauso Command als PChar, da das sicherlich ein Text/String sein wird, oder?

Ansonsten passt das so schon, wenn ich grad nix übersehen hab.

_________________
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.
OlafSt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 486
Erhaltene Danke: 99

Win7, Win81, Win10
Tokyo, VS2017
BeitragVerfasst: Mo 10.10.11 16:04 
Danke fürs verschieben, ich wäre nicht darauf gekommen, das ganze unter "Dateizugriff" einzusortieren ;)

Die Idee mit "var ResponseLen: Word" finde ich gut - werds sofort ausprobieren. PAnsiChar habe ich deswegen gewählt, da ich hier einen D2010-Compiler habe, wo alles Unicode ist - auch ein Char ist nun ein 2-Byte-Char. Um da Problemen aus dem Weg zu gehen, hab ich PAnsiChar (also definitive 1-Byte-Chars) genommen.

Was den Rückgabewert angeht: char ist doch ein signed byte in C ? Dann wäre "byte" als Resulttyp falsch, da dies in Pascal unsigned ist - ich jedoch auch negative Werte im Fehlerfall zurückbekomme. Darum fiel meine Wahl auf ShortInt.

[Edit] Erste Tests haben egeben: Funktioniert prima mi var ResponseLen: Word. Danke dir, Ben !

_________________
Lies, was da steht. Denk dann drüber nach. Dann erst fragen.


Zuletzt bearbeitet von OlafSt am Mo 10.10.11 16:20, insgesamt 1-mal bearbeitet
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: Mo 10.10.11 16:16 
Dann müsstest Du SmallInt und nicht ShortInt nehmen, weil ShortInt 16 Bit, ein SmallInt aber nur 8 Bit sind.

Meinte zusätzlich PAnsiChar für Source und Dest.

_________________
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.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 10.10.11 19:08 
user profile iconBenBE hat folgendes geschrieben Zum zitierten Posting springen:
Dann müsstest Du SmallInt und nicht ShortInt nehmen, weil ShortInt 16 Bit, ein SmallInt aber nur 8 Bit sind.
Genau andersrum, user profile iconOlafSt hats schon richtig.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."