![]() |
Problem mit C++ DLL mit Stringfunktionen
Hallo DPler,
ich versuche schon seit ein paar Tagen Funktionen aus einer C++ DLL zu nutzen, leider hab ich das bis her noch nicht hinbekommen, da einige Funktionen in der DLL Strings als Argumente erwarten. Ich hoffe ihr könnt mir sagen was ich falsch mache oder wie ich es machen muss damit es funktioniert. Hier mein Delphi Code:
Delphi-Quellcode:
So deklariert der Autor der DLL die Funktionen im
unit Unit1;
interface uses Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShareMem; function ohs_set_password(PW: string): Double; stdcall; function ohs_get_status: Double; stdcall; function ohs_get_position: Double; stdcall; function ohs_table_clear: Double; stdcall; function ohs_table_update: Double; stdcall; function ohs_table_get(Spalte: Double; Reihe: Double): string; stdcall; function ohs_header_get(Spalte: Double): string; stdcall; function ohs_table_columns: Double; stdcall; function ohs_table_rows: Double; stdcall; function ohs_submit_add(Spalte: Double; Wert: string): Double; stdcall; function ohs_submit_clear: Double; stdcall; function ohs_set_url(URL: string; Pfad: string): Double; stdcall; function ohs_set_table(Tabelle: string): Double; stdcall; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Label2: TLabel; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} function ohs_set_password(PW: string): Double; stdcall; external 'ohs.dll'; function ohs_get_status: Double; stdcall; external 'ohs.dll'; function ohs_get_position: Double; stdcall; external 'ohs.dll'; function ohs_table_clear: Double; stdcall; external 'ohs.dll'; function ohs_table_update: Double; stdcall; external 'ohs.dll'; function ohs_table_get(Spalte: Double; Reihe: Double): string; stdcall; external 'ohs.dll'; function ohs_header_get(Spalte: Double): string; stdcall; external 'ohs.dll'; function ohs_table_columns: Double; stdcall; external 'ohs.dll'; function ohs_table_rows: Double; stdcall; external 'ohs.dll'; function ohs_submit_add(Spalte: Double; Wert: string): Double; stdcall; external 'ohs.dll'; function ohs_submit_clear: Double; stdcall; external 'ohs.dll'; function ohs_set_url(URL: string; Pfad: string): Double; stdcall; external 'ohs.dll'; function ohs_set_table(Tabelle: string): Double; stdcall; external 'ohs.dll'; procedure TForm1.Button1Click(Sender: TObject); begin ohs_set_url(PChar('http://muti.mu.funpic.de'), PChar('/OHS')); ohs_set_table(PChar('TEST')); ohs_set_password(Pchar('12345')); Label1.Caption:= FloatToStr(ohs_table_update); ohs_submit_add(0, PChar('Test')); ohs_submit_add(1, PChar('300')); Label1.Caption:= FloatToStr(ohs_table_update); Label2.Caption:= FloatToStr(ohs_get_position); end; ![]()
Code:
#define ohs_init
global.dll_ohs_set_password = external_define("ohs.dll","ohs_set_password",dll_stdcall,ty_real,1,ty_string); global.dll_ohs_set_url = external_define("ohs.dll","ohs_set_url",dll_stdcall,ty_real,2,ty_string,ty_string); global.dll_ohs_set_table = external_define("ohs.dll","ohs_set_table",dll_stdcall,ty_real,1,ty_string); global.dll_ohs_get_status = external_define("ohs.dll","ohs_get_status",dll_stdcall,ty_real,0); global.dll_ohs_get_position = external_define("ohs.dll","ohs_get_position",dll_stdcall,ty_real,0); global.dll_ohs_table_clear = external_define("ohs.dll","ohs_table_clear",dll_stdcall,ty_real,0); global.dll_ohs_table_update = external_define("ohs.dll","ohs_table_update",dll_stdcall,ty_real,0); global.dll_ohs_table_get = external_define("ohs.dll","ohs_table_get",dll_stdcall,ty_string,2,ty_real,ty_real); global.dll_ohs_header_get = external_define("ohs.dll","ohs_header_get",dll_stdcall,ty_string,1,ty_real); global.dll_ohs_table_columns = external_define("ohs.dll","ohs_table_columns",dll_stdcall,ty_real,0); global.dll_ohs_table_rows = external_define("ohs.dll","ohs_table_rows",dll_stdcall,ty_real,0); global.dll_ohs_submit_add = external_define("ohs.dll","ohs_submit_add",dll_stdcall,ty_real,2,ty_real,ty_string); global.dll_ohs_submit_clear = external_define("ohs.dll","ohs_submit_clear",dll_stdcall,ty_real,0); |
Re: Problem mit C++ DLL mit Stringfunktionen
C -Strings sind nicht Delphi Strings. Nutze PChars an deren Stelle.
|
Re: Problem mit C++ DLL mit Stringfunktionen
Hallo,
1. sharemem raus 2. String durch PChar ersetzen Ansonsten verstehe ich das ganze überhaupt nicht. Die gmaker.pdf auf der Seite erzählt was von Einbinden fremder DLLs (auch in Delphi geschrieben). Musst halt ein bissel probieren. Heiko |
Re: Problem mit C++ DLL mit Stringfunktionen
Liste der Anhänge anzeigen (Anzahl: 1)
Leider Klapt es auch nicht mit PChars und ohne Sharemem ich bekomme immer komische werte zurück.
Die DLL ist eine schnitt stell zur einem Online Highscore system, was für den GM gemacht wurde. Da ich das System ganz gut fand wollte ich es auch nutzen und der Autor meinte das es eigentlich keine Probleme geben sollte wenn ich die DLL in Delphi nutzen will. Die Header Datei zu der DLL wollte der Autor nicht hergeben :(. Ich hab mal im anhang die DLL + Readme + mein Test Programm beigefügt, die URL, Tabellenname und das PW sind richtig so. Habe zum testen das OHS system auf meinem Webspace Installiert. Nur die DLL bereitet mir noch Kopfzerbrechen. Edit: Hier noch der Link zur ![]() |
Re: Problem mit C++ DLL mit Stringfunktionen
In der ohs.gml steht zwar "dll_stdcall" (was man als __stdcall interpretieren könnte), aber im Disassembler sehen alle von der ohs.dll exportierten Funktionen nach __cdecl aus.
Edit: Und anstatt Double (C/C++ double: 8 Bytes) würde ich mal Single (C/C++ float: 4 Bytes) probieren. |
Re: Problem mit C++ DLL mit Stringfunktionen
Leider klappt es auch mit cdecl nicht und ich habe schon alles mögliche ausprobiert mit real, double, single, float, string, char und pchar es hat bis jetzt noch nicht geklappt. Mache ich vielleicht irgendwas beim Aufruf der DLL falsch?
|
Re: Problem mit C++ DLL mit Stringfunktionen
Hallo alle zusammen,
So ich habe nun die Header Datei zu der DLL von dem Autor bekommen und Code dem entsprechend angepasst, leider scheint es noch immer nicht zu klappen. Könnte mir vielleicht irgendjemand helfen? Hier mein Code:
Delphi-Quellcode:
Hier die Header Datei zur DLL:
function ohs_set_password(const PW: PChar): Double; stdcall;
function ohs_get_status: Double; stdcall; function ohs_get_position: Double; stdcall; function ohs_table_clear: Double; stdcall; function ohs_table_update: Double; stdcall; function ohs_table_get(Spalte: Double; Reihe: Double): PChar; stdcall; function ohs_header_get(Spalte: Double): PChar; stdcall; function ohs_table_columns: Double; stdcall; function ohs_table_rows: Double; stdcall; function ohs_submit_add(Spalte: Double; const Wert: PChar): Double; stdcall; function ohs_submit_clear: Double; stdcall; function ohs_set_url(const URL: PChar; const Pfad: PChar): Double; stdcall; function ohs_set_table(const Tabelle: PChar): Double; stdcall;
Code:
#define export extern "C" __declspec (dllexport)
export double ohs_set_password(const char * pw); export double ohs_set_url(const char * h, const char * p); export double ohs_set_table(const char * tab); export double ohs_get_status(); export double ohs_get_position(); export double ohs_table_update(); export double ohs_table_clear(); export const char * ohs_table_get(double col, double row); export const char * ohs_header_get(double col); export double ohs_table_columns(); export double ohs_table_rows(); export double ohs_submit_add(double col, const char * value); export double ohs_submit_clear(); |
Re: Problem mit C++ DLL mit Stringfunktionen
Mal cdecl an Stelle von stdcall versucht ?
|
Re: Problem mit C++ DLL mit Stringfunktionen
Zitat:
|
Re: Problem mit C++ DLL mit Stringfunktionen
Liste der Anhänge anzeigen (Anzahl: 1)
Mir kommt es so vor als ob es das macht was es machen soll.
Stimmt denn auch die Vorgehensweise wie eine Tabelle angelegt wird, das Passwort etc. ? |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:32 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz