AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Problem mit Aufruf einer Funktion in externen dll
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit Aufruf einer Funktion in externen dll

Ein Thema von schlagzu · begonnen am 13. Aug 2011 · letzter Beitrag vom 14. Aug 2011
Antwort Antwort
schlagzu

Registriert seit: 11. Okt 2010
86 Beiträge
 
Delphi XE Starter
 
#1

AW: Problem mit Aufruf einer Funktion in externen dll

  Alt 13. Aug 2011, 19:53
Danke für die schnelle Hilfe, es tut sich dennoch nichts.
Es handelt sich bei der dll, um Schnittstelle für ein display. Den Kontrast oder die Helligkeit kann ich verstellen, nur eben schreiben will nicht funktionieren. Die dll stammt von der Software lcd smartie, ich will einfach nur eine schlankere kleine Version für mich, darum habe ich mir gedacht das ich die dll einfach verenden kann. Aber irgendwo muss ja ein Fehler sein, denn die dll funktioniert mit der Software.

Falls jemand noch ne Idee hat bitte teilt sie mir mit.

Delphi-Quellcode:
procedure TForm1.Button4Click(Sender: TObject);
var s:AnsiString;
begin
  s:='abcdefgh';
  DISPLAYDLL_Write(pansichar(s));
end;
  Mit Zitat antworten Zitat
schlagzu

Registriert seit: 11. Okt 2010
86 Beiträge
 
Delphi XE Starter
 
#2

AW: Problem mit Aufruf einer Funktion in externen dll

  Alt 13. Aug 2011, 20:03
Fehler gefunden!

Ich muss eine reihe voll machen, bevor sie angezeigt wird!
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.384 Beiträge
 
Delphi 12 Athens
 
#3

AW: Problem mit Aufruf einer Funktion in externen dll

  Alt 14. Aug 2011, 06:44
Man kann das Ganze jetzt noch etwas delphitypischer anpssen.

Delphi-Quellcode:
interface

type
  MatrixDisplay = record
    const Matrix = 'matrix.dll';
    class function Init(SizeX, SizeY: Byte; S: AnsiString; var OK: Boolean): PAnsiChar; stdcall; static;
    class function Done: PAnsiChar; stdcall; static;
    class procedure Write(Str: AnsiString); stdcall; static;
    class function DefaultParameters: PAnsiChar; stdcall; static;
    class function SetPosition(x, y: Byte): PAnsiChar; stdcall; static;
    class procedure SetBrightness(Brightness: Byte); stdcall; static;
    class procedure SetContrast(Contrast: Byte); stdcall; static;
    class procedure SetGPO(GPO: Byte; GPOOn: Boolean); stdcall; static;
    class procedure SetFan(T1, T2: Byte); stdcall; static;
    class procedure SetBacklight(LightOn: Boolean); stdcall; static;
    class procedure CustomChar(Chr: Byte; Data: TCustomArray); stdcall; static;
  end;

implementation

class function MatrixDisplay.Init; external MatrixDisplay.Matrix name 'DISPLAYDLL_Init';
class function MatrixDisplay.Done; external MatrixDisplay.Matrix name 'DISPLAYDLL_Done';
class procedure MatrixDisplay.Write; external MatrixDisplay.Matrix name 'DISPLAYDLL_Write';
class function MatrixDisplay.DefaultParameters; external MatrixDisplay.Matrix name 'DISPLAYDLL_DefaultParameters';
class function MatrixDisplay.SetPosition; external MatrixDisplay.Matrix name 'DISPLAYDLL_SetPosition';
class procedure MatrixDisplay.SetBrightness; external MatrixDisplay.Matrix name 'DISPLAYDLL_SetBrightness';
class procedure MatrixDisplay.SetContrast; external MatrixDisplay.Matrix name 'DISPLAYDLL_SetContrast';
class procedure MatrixDisplay.SetGPO; external MatrixDisplay.Matrix name 'DISPLAYDLL_SetGPO';
class procedure MatrixDisplay.SetFan; external MatrixDisplay.Matrix name 'DISPLAYDLL_SetFan';
class procedure MatrixDisplay.SetBacklight; external MatrixDisplay.Matrix name 'DISPLAYDLL_SetBacklight';
class procedure MatrixDisplay.CustomChar; external MatrixDisplay.Matrix name 'DISPLAYDLL_CustomChar';
Und nochmal, wegen dem immernoch defekten Delphi-Tags:
Code:
interface

type
  MatrixDisplay = record
    const Matrix = 'matrix.dll';
    class function  Init(SizeX, SizeY: Byte; S: AnsiString; var OK: Boolean): PAnsiChar; stdcall; static;
    class function  Done: PAnsiChar; stdcall; static;
    class procedure Write(Str: AnsiString); stdcall; static;
    class function  DefaultParameters: PAnsiChar; stdcall; static;
    class function  SetPosition(x, y: Byte): PAnsiChar; stdcall; static;
    class procedure SetBrightness(Brightness: Byte); stdcall; static;
    class procedure SetContrast(Contrast: Byte); stdcall; static;
    class procedure SetGPO(GPO: Byte; GPOOn: Boolean); stdcall; static;
    class procedure SetFan(T1, T2: Byte); stdcall; static;
    class procedure SetBacklight(LightOn: Boolean); stdcall; static;
    class procedure CustomChar(Chr: Byte; Data: TCustomArray); stdcall; static;
  end;

implementation

class function  MatrixDisplay.Init;              external MatrixDisplay.Matrix name 'DISPLAYDLL_Init';
class function  MatrixDisplay.Done;              external MatrixDisplay.Matrix name 'DISPLAYDLL_Done';
class procedure MatrixDisplay.Write;             external MatrixDisplay.Matrix name 'DISPLAYDLL_Write';
class function  MatrixDisplay.DefaultParameters; external MatrixDisplay.Matrix name 'DISPLAYDLL_DefaultParameters';
class function  MatrixDisplay.SetPosition;       external MatrixDisplay.Matrix name 'DISPLAYDLL_SetPosition';
class procedure MatrixDisplay.SetBrightness;     external MatrixDisplay.Matrix name 'DISPLAYDLL_SetBrightness';
class procedure MatrixDisplay.SetContrast;       external MatrixDisplay.Matrix name 'DISPLAYDLL_SetContrast';
class procedure MatrixDisplay.SetGPO;            external MatrixDisplay.Matrix name 'DISPLAYDLL_SetGPO';
class procedure MatrixDisplay.SetFan;            external MatrixDisplay.Matrix name 'DISPLAYDLL_SetFan';
class procedure MatrixDisplay.SetBacklight;      external MatrixDisplay.Matrix name 'DISPLAYDLL_SetBacklight';
class procedure MatrixDisplay.CustomChar;        external MatrixDisplay.Matrix name 'DISPLAYDLL_CustomChar';
Statt record könnte man auch class
PAnsiChar als Result wird automatisch von Delphi in einen String convertiert, wenn man es an einen String zuweisen will
und der AnsiString-Parameter wird quasi auch automatisch konvertiert, denn der String-Typ ist PChar-kompatibel aufgebaut.
PBoolean ist eine Referenz auf einen Boolean, was ein Var-Parameter ebenfalls ist.


Beim Boolean mußt du aufpassen.
Wie ist der denn im Original deklariert?

Boolean, bzw. ByteBool = 1 Byte
LongBool = 4 Byte (Integer)
und das BOOL in C++ ist ein LongBool im Delphi.



Was ist denn TCustomArray?
Delphi-Quellcode:
MatrixDisplay.Init(...);

// ********

type
  MD = MatrixDisplay;

MD.Init(...);

// ********

var
  MD: MatrixDisplay; // ist 0 Byte groß uns läßt sich sehr schön als lokale Variable nutzen (records sind toll)

MD.Init(...);
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu (14. Aug 2011 um 06:57 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:33 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