Delphi-PRAXiS
Seite 1 von 4  1 23     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi DLL einbinden octopus.dll (https://www.delphipraxis.net/117654-dll-einbinden-octopus-dll.html)

multi-man 22. Jul 2008 22:59


DLL einbinden octopus.dll
 
Hallo !

Ich habe folgendes Problem :

Ich habe einen OctopusUSB ( Hier der Link )
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:
/*
 * 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;
}
Dass ich diese mit
Delphi-Quellcode:
function octopus_init(context: octopus_context): integer; external 'octopus.dll';
aufrufen kann ist klar, aber was mache ich eben mit den Übergabewert "*octopus" ?

Das struct octopus_context ist wie folgt definiert :
Code:
struct octopus_context {
   // USB specific
   /// libusb's usb_dev_handle
   struct usb_dev_handle *usb_handle;

   /// String representation of last error
   char *error_str;
};
Ich habe es versucht mit folgendem record zu übersetzen :

Delphi-Quellcode:
  usb_device_handle = Record
  end;

  octopus_context = record
      usb_handle : usb_device_handle;
      error_str : string;
  end;
aber der Inhalt bleibt leer, und sobald ich eine andere Funktion aufrufen möchte, kommt eine exception ...

Ich hoffe mir kann jemand helfen

mfg
Chris

multi-man 23. Jul 2008 00:40

Re: DLL einbinden octopus.dll
 
Hier nochmal ein paar Hintergrundinfos zu dem Teil :

Downloads-Section auf Embedded-projects.net

Hier gibt es ein Handbuch zu dem Teil (allerdings noch im Aufbau)

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

multi-man 23. Jul 2008 20:44

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 .. :(

omata 23. Jul 2008 20:49

Re: DLL einbinden octopus.dll
 
versuch es doch mal so...
Delphi-Quellcode:
function octopus_init(var context: octopus_context): integer; external 'octopus.dll';

multi-man 23. Jul 2008 21:03

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

Luckie 23. Jul 2008 21:10

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?

omata 23. Jul 2008 21:13

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;

multi-man 23. Jul 2008 21:17

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.

multi-man 23. Jul 2008 21:27

Re: DLL einbinden octopus.dll
 
Zitat:

Zitat von omata
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;

Habe ich probiert, aber leider will es so auch nicht, er bekommt zwar ne 1 zurück, aber anschliessend kommt gleich wieder ne exception... Hab mal geschaut, also der wert von context ist vor dem Aufruf der DLL natürlich irgendein Wert, wenn die DLL-Funktion aber vorbei ist, dann ist context NIL ...

omata 24. Jul 2008 02:07

Re: DLL einbinden octopus.dll
 
Versuch es mal so...
Delphi-Quellcode:
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';
Aufruf...
Delphi-Quellcode:
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;
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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:11 Uhr.
Seite 1 von 4  1 23     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz