Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi COM / DLL-Einbindung für Anfänger (https://www.delphipraxis.net/213909-com-dll-einbindung-fuer-anfaenger.html)

wurzelsepp1 17. Okt 2023 17:08

COM / DLL-Einbindung für Anfänger
 
Moin Gemeinde,

wieder eine der fürchterlichen Anfängerfragen:

Ich möchte einige Funktionen aus einer externen Druck-DLL nutzen. Der Compiler stolpert aber über eine fehlerhafte Einbindung (forward-Deklaration):

Wrapper (Auszug):
Delphi-Quellcode:
const
IID_IDymoAddIn: TGUID = '{09DAFAE1-8EB0-11D2-8E5D-00A02415E90F}';

type
IDymoAddIn = interface;

IDymoAddIn = interface(IDispatch)
    ['{09DAFAE1-8EB0-11D2-8E5D-00A02415E90F}']
    function Open(const FileName: WideString): WordBool; safecall;
    function Save: WordBool; safecall;
    function SaveAs(const FileName: WideString): WordBool; safecall;
    function Print(Copies: Integer; bShowDialog: WordBool): WordBool; safecall;
    procedure Hide; safecall;
    procedure Show; safecall;
    procedure SysTray(State: WordBool); safecall;
    procedure Quit; safecall;
    function Get_FileName: WideString; safecall;
    function SelectPrinter(const Printer: WideString): WordBool; safecall;
    function GetDymoPrinters: WideString; safecall;
    property FileName: WideString read Get_FileName;
  end;
Und dann der Aufruf der externen Funktion aus der Delphi App:

Delphi-Quellcode:
pfad := 'mylabel.lwl';
opened := DymoAddIn.Open(pfad);
Da gibts dann den Fehler "E2018 Record, Objekt oder Klassentyp erforderlich".

Wie macht man das noch richtig? ;-)

Danke!

himitsu 17. Okt 2023 17:16

AW: COM / DLL-Einbindung für Anfänger
 
Was ist DymoAddIn?

Und wenn ja, von wo kommt wie die Instanz her?

wurzelsepp1 17. Okt 2023 17:37

AW: COM / DLL-Einbindung für Anfänger
 
Zitat:

Zitat von himitsu (Beitrag 1528276)
Was ist DymoAddIn?

Eine Funktion in einer DLL des Druckerherstellers.

Zitat:

Zitat von himitsu (Beitrag 1528276)
Und wenn ja, von wo kommt wie die Instanz her?

Die ist in dem Wrapper definiert:

Delphi-Quellcode:
 LIBID_Dymo: TGUID = '{DC8A996F-111D-42E2-BACF-EEC86F53B454}';
 IID_IDymoAddIn: TGUID = '{09DAFAE1-8EB0-11D2-8E5D-00A02415E90F}';
Wenn da weitere Ausschnitte benötigt werden, schicke ich die gerne.

Kas Ob. 17. Okt 2023 18:31

AW: COM / DLL-Einbindung für Anfänger
 
E2018 is Delphi compiler error.
Please share a simple code showing how are you declaring DymoAddIn and its construction.

wurzelsepp1 17. Okt 2023 19:59

AW: COM / DLL-Einbindung für Anfänger
 
Zitat:

Zitat von Kas Ob. (Beitrag 1528280)
E2018 is Delphi compiler error.
Please share a simple code showing how are you declaring DymoAddIn and its construction.

I think I did. Here is the wrapper (only the part with the function I need to use):

Delphi-Quellcode:
const

  LIBID_DymoSDK: TGUID = '{25D837F1-8D49-3354-A820-AE8ED312EC09}';

  IID_IDymoLabel: TGUID = '{5748221F-3D1E-35AE-8F26-4D01C9798FE9}';
  IID_IDymoPrinter: TGUID = '{2BED54B5-C7F6-3939-973A-AFB075AB9572}';

type

// *********************************************************************//
// Forward-Deklaration von in der Typbibliothek definierten Typen                    
// *********************************************************************//
  IDymoLabel = interface;
  IDymoPrinter = interface;

// *********************************************************************//
// Interface: IDymoLabel
// Flags:    (4416) Dual OleAutomation Dispatchable
// GUID:     {5748221F-3D1E-35AE-8F26-4D01C9798FE9}
// *********************************************************************//
  IDymoLabel = interface(IDispatch)
    ['{5748221F-3D1E-35AE-8F26-4D01C9798FE9}']
    function Get_XMLContent: WideString; safecall;
    procedure Set_XMLContent(const pRetVal: WideString); safecall;
    function Get_Preview: PSafeArray; safecall;
    procedure Set_Preview(pRetVal: PSafeArray); safecall;
    function GetPreviewLabel: PSafeArray; safecall;
    procedure LoadLabelFromFilePath(const filePath: WideString); safecall;
    procedure LoadLabelFromXML(const XMLContent: WideString); safecall;
    function UpdateLabelObject(const labelObject: ILabelObject; const objectValue: WideString): WordBool; safecall;
    function SetImageFromFilePath(const objectName: WideString; const imageFile: WideString): WordBool; safecall;
    function SetImageFromBase64(const objectName: WideString; const base64String: WideString): WordBool; safecall;
    function Save(const fileName: WideString): WordBool; safecall;
    function GetLabelObject(const objName: WideString): ILabelObject; safecall;
    procedure GhostMethod_IDymoLabel_72_1; safecall;
    property XMLContent: WideString read Get_XMLContent write Set_XMLContent;
    property Preview: PSafeArray read Get_Preview write Set_Preview;
  end;

HTH

Olli73 17. Okt 2023 20:46

AW: COM / DLL-Einbindung für Anfänger
 
Delphi-Quellcode:
Var
  MyDymoAddIn: IDymoAddIn;

...

MyDymoAddIn := DymoAddIn;
MyDymoAddIn.open(...);
...

wurzelsepp1 4. Nov 2023 12:46

AW: COM / DLL-Einbindung für Anfänger
 
Zitat:

Zitat von Olli73 (Beitrag 1528282)
Delphi-Quellcode:
Var
  MyDymoAddIn: IDymoAddIn;

...

MyDymoAddIn := DymoAddIn;
MyDymoAddIn.open(...);
...

Genau so funktioniert's. Vielen Dank! :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:45 Uhr.

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