![]() |
DLL einbinden octopus.dll
Hallo !
Ich habe folgendes Problem : Ich habe einen OctopusUSB ( ![]() Das ist ein Ein/Ausgabe Interface für den Anschluss an USB. Ich habe es mir bestellt, da ich dachte, ich bekomme es auch mit Delphi angesteuert, allerdings komme ich nicht richtig weiter... Dabei ist eine octopus.dll Diese exportiert unter anderem eine Funktion "octopus_init" :
Code:
Dass ich diese mit
/*
* initial octopus handle before use octopus_open */ int octopus_init(struct octopus_context *octopus) { if (octopus == NULL) octopus_error_return(-1,"octopus not valid"); octopus->error_str = NULL; octopus->usb_handle = NULL; return 1; }
Delphi-Quellcode:
aufrufen kann ist klar, aber was mache ich eben mit den Übergabewert "*octopus" ?
function octopus_init(context: octopus_context): integer; external 'octopus.dll';
Das struct octopus_context ist wie folgt definiert :
Code:
Ich habe es versucht mit folgendem record zu übersetzen :
struct octopus_context {
// USB specific /// libusb's usb_dev_handle struct usb_dev_handle *usb_handle; /// String representation of last error char *error_str; };
Delphi-Quellcode:
aber der Inhalt bleibt leer, und sobald ich eine andere Funktion aufrufen möchte, kommt eine exception ...
usb_device_handle = Record
end; octopus_context = record usb_handle : usb_device_handle; error_str : string; end; Ich hoffe mir kann jemand helfen mfg Chris |
Re: DLL einbinden octopus.dll
Hier nochmal ein paar Hintergrundinfos zu dem Teil :
![]() ![]() In C ist es ohne Probleme ansprechbar, allerdings will ich nicht erst ein C-Prog coden, dass ich dann von der Delphi-App fernsteuern lasse ;-) Ich hoffe auf eure Tipps mfg Chris |
Re: DLL einbinden octopus.dll
Falls ich ins falsche Forum gepostet habe, oder einfach zu wenige Informationen wäre ich auch über einen Hinweis dankbar .. :(
|
Re: DLL einbinden octopus.dll
versuch es doch mal so...
Delphi-Quellcode:
function octopus_init(var context: octopus_context): integer; external 'octopus.dll';
|
Re: DLL einbinden octopus.dll
Liste der Anhänge anzeigen (Anzahl: 1)
Es gab wieder denselben fehler, habe den Fehler mal als screenshot angehängt ...
|
Re: DLL einbinden octopus.dll
Zeig doch mal den ganzen Code. Wie rufst du die Funktion denn auf? hast du auch entsprechend Speicher reserviert? Und wie sieht es mit den Aufrufkonventionen aus? Standardmäßig nimmt Delphi, wenn nichts anderes angegeben ist Register. C-DLLs, die auch für andere Programmiersprachen gedacht sind nehmen meist stdcall. Was sagt denn die Dokumentation dazu?
|
Re: DLL einbinden octopus.dll
eventuell sind das alles Zeiger...
Delphi-Quellcode:
type
usb_device_handle = record end; Pusb_device_handle = ^usb_device_handle; octopus_context = record usb_handle : Pusb_device_handle; error_str : pchar; end; Poctopus_context = ^octopus_context;
Delphi-Quellcode:
function octopus_init(context: Poctopus_context): integer; stdcall; external 'octopus.dll';
Delphi-Quellcode:
var context:Poctopus_context;
begin new(context); if octopus_init(context) <> 0 then begin end; end; |
Re: DLL einbinden octopus.dll
Speicher reserviert ? Wohl eher nicht :(
Aber hier mal der Code :
Delphi-Quellcode:
unit octopusU1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; type usb_device_handle = Record end; octopus_context = record usb_handle : usb_device_handle; error_str : string; end; var Form1: TForm1; oc1 : octopus_context; implementation {$R *.dfm} function octopus_init(var context: octopus_context): integer; external 'octopus.dll'; function octopus_get_hwdesc(var context: octopus_context; desc: Pchar): Pchar; external 'octopus.dll'; function octopus_open(context: octopus_context): integer; external 'octopus.dll'; procedure TForm1.Button1Click(Sender: TObject); var erg : integer; desc1, desc2 : Pchar; begin erg := octopus_init(oc1); desc1 := octopus_get_hwdesc(oc1,desc2); form1.Caption := inttostr(erg); end; end. |
Re: DLL einbinden octopus.dll
Zitat:
|
Re: DLL einbinden octopus.dll
Versuch es mal so...
Delphi-Quellcode:
Aufruf...
type
octopus_context = packed record usb_handle : integer; error_str : pchar; end; Poctopus_context = ^octopus_context; function octopus_init(context: Poctopus_context): integer; stdcall; external 'octopus.dll'; function octopus_open(context: Poctopus_context): integer; stdcall; external 'octopus.dll';
Delphi-Quellcode:
Das Init läuft durch, beim Open erhalte ich die folgende Meldung: "could not found octopus device with pid and vid". Diese Meldung ist ja schonmal vielversprechend, ich habe ja auch kein Gerät. Aber es kommt eben auch keine Access Violation mehr.
var context:Poctopus_context;
begin new(context); try if octopus_init(context) = 0 then raise Exception.Create(context.error_str); if octopus_open(context) < 0 then raise Exception.Create(context.error_str); finally dispose(context); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:22 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