AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

DLL - C nach Delphi konvertieren

Ein Thema von ich2 · begonnen am 6. Mär 2017 · letzter Beitrag vom 6. Mär 2017
Antwort Antwort
Benutzerbild von ich2
ich2

Registriert seit: 7. Dez 2005
Ort: Würzburg
54 Beiträge
 
#1

DLL - C nach Delphi konvertieren

  Alt 6. Mär 2017, 08:41
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
Angehängte Dateien
Dateityp: rar Delphi_DobotInterface.rar (4,04 MB, 5x aufgerufen)
Wissen ist Macht. Das ändert aber so gut wie nichts an der Übermacht der Dummheit.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: DLL - C nach Delphi konvertieren

  Alt 6. Mär 2017, 09:42
Hast Du es mal mit packed record versucht?
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#3

AW: DLL - C nach Delphi konvertieren

  Alt 6. Mär 2017, 09:54
...zumindest funktioniert nur ein Teil der Kommandos...
Welche Symptome?

Ersetze "Boolean" durch "LongBool".

TPTPCmd = packed record
  Mit Zitat antworten Zitat
Benutzerbild von ich2
ich2

Registriert seit: 7. Dez 2005
Ort: Würzburg
54 Beiträge
 
#4

AW: DLL - C nach Delphi konvertieren

  Alt 6. Mär 2017, 13:08
Hallo zusammen,

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

Läuft
Wissen ist Macht. Das ändert aber so gut wie nichts an der Übermacht der Dummheit.
  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 00:17 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