Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   DLL - C nach Delphi konvertieren (https://www.delphipraxis.net/191940-dll-c-nach-delphi-konvertieren.html)

ich2 6. Mär 2017 08:41

DLL - C nach Delphi konvertieren
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo liebe Community,

bei der Übersetzung eines Headers für den Zugriff auf eine DLL scheint ein Fehler zu sein...zumindest funktioniert nur ein Teil der Kommandos...

Auszug aus der DobotDll.h Datei:
Code:
#ifndef DOBOTDLL_H
#define DOBOTDLL_H

#include "DobotType.h"

...

extern "DobotDll.dll" int SetPTPCmd(PTPCmd *ptpCmd, bool isQueued, uint64_t *queuedCmdIndex);

...

#endif // DOBOTDLL_H
und Auszug aus der DobotType.h Datei

Code:
#ifndef DOBOTTYPE_H
#define DOBOTTYPE_H

#ifdef _MSC_VER
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned long long uint64_t;
typedef signed long long int64_t;
#else
#include <stdint.h>
#endif

...

#pragma pack(push)
#pragma pack(1)

...

typedef struct tagPTPCmd {
    uint8_t ptpMode;
    float x;
    float y;
    float z;
    float r;
}PTPCmd;

...

#pragma pack(pop)
#endif
...dann noch ein weiterer Auszug aus einem C# Beispiel:

DobotDllType.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DobotClientDemo.CPlusDll

...

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct PTPCmd
    {
        public byte ptpMode;
        public float x;
        public float y;
        public float z;
        public float rHead;
    };

...

}
und aus der Dobot.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DobotClientDemo.CPlusDll

...

        [DllImport("DobotDll.dll", EntryPoint = "SetPTPCmd", CallingConvention = CallingConvention.Cdecl)]
        public static extern int SetPTPCmd(ref PTPCmd playbackCmd, bool isQueued, ref UInt64 queuedCmdIndex);


...

}

...an sich alles kein Problem, nun der übersetzte Part in Delphi:

Delphi-Quellcode:
unit UDobot_Interface;

interface

type

...

  TPTPCmd = record
    ptpMode: Byte;
    x: single;
    y: single;
    z: single;
    r: single;
  end;
  PPTPCmd = ^TPTPCmd;

...

  function SetPTPCmd ( ptpCmd: PPTPCmd; isQueued: Boolean; queuedCmdIndex: puint64 ): Integer; cdecl;

...

implementation

...

  //extern "C" int SetPTPCmd(PTPCmd *ptpCmd, bool isQueued, uint64_t *queuedCmdIndex);
  function SetPTPCmd ( ptpCmd: PPTPCmd; isQueued: Boolean; queuedCmdIndex: puint64 ): Integer;
  cdecl; external 'DobotDll.dll';

...

end.
...ist da irgendwo ein Fehler?

Danke für Hinweise

Grüße

DeddyH 6. Mär 2017 09:42

AW: DLL - C nach Delphi konvertieren
 
Hast Du es mal mit packed record versucht?

Blup 6. Mär 2017 09:54

AW: DLL - C nach Delphi konvertieren
 
Zitat:

Zitat von ich2 (Beitrag 1363274)
...zumindest funktioniert nur ein Teil der Kommandos...

Welche Symptome?

Ersetze "Boolean" durch "LongBool".

Delphi-Quellcode:
TPTPCmd = packed record

ich2 6. Mär 2017 13:08

AW: DLL - C nach Delphi konvertieren
 
Hallo zusammen,

vielen Dank für die schnellen Antworten:
Ersetzen von Boolean durch LongBool und ein packed dazu hat Wunder gewirkt.

Läuft :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:40 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