Autor Beitrag
Edmund Jenner-Braunschmie
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 34

WIN XP Professional
D2009 Professional
BeitragVerfasst: Mo 15.01.07 10:05 
Hallo Leute,

ich habe immer noch ein Problem beim Übersetzen eines Quelltextes aus C++ ins Delphi:

Die Funktion "VRmUsbCamNewImage" (ist in einer DLL) gibt immer FAILED zurück. Ich glaube das
Problem liegt in der Struktur für das VRmImage. Siehe unten die Codes!!

Was bedeutet
VRmBYTE* mp_buffer;
??

Ist das ein Pointer auf ein Byte bzw. Char? In dem mp_buffer sollten nach erfolgreicher
Ausführung der Funktion eigentlich alle Daten eines Image (ähnlich wie eine Bitmap) liegen. Wie
kann das als Pointer auf 1 Byte funktionieren.

Ach Gott C++ und die Pointer.....

Bitte um Hilfe und liebe Grüße

Edi

Hier der relevante C-Code:

ausblenden C-Code
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
  typedef unsigned char VRmBYTE; 
  typedef unsigned short int VRmWORD;
  typedef unsigned long int VRmDWORD; 
  typedef unsigned int VRmBOOL;

  typedef enum _VRmColorFormat
    { VRM_ARGB_4X8, VRM_BGR_3X8, VRM_RGB_565, VRM_YUYV_4X8, VRM_GRAY_8, VRM_BAYER_GBRG_8, VRM_BAYER_BGGR_8, VRM_BAYER_RGGB_8,
      VRM_BAYER_GRBG_8, VRM_GRAY_10, VRM_BAYER_GBRG_10, VRM_BAYER_BGGR_10, VRM_BAYER_RGGB_10, VRM_BAYER_GRBG_10
    }VRmColorFormat;

  /// struct for image format  
  typedef struct _VRmImageFormat
    { VRmDWORD m_width;
      VRmDWORD m_height;
      VRmColorFormat m_color_format;
      int m_image_modifier;
    }VRmImageFormat;

  /// struct for image container
  typedef struct _VRmImage
    { VRmImageFormat m_image_format;
      VRmBYTE* mp_buffer;
      VRmDWORD m_pitch;
      double m_time_stamp;
      void* mp_private;
    }VRmImage;

  /// create new image with given image format,
  /// free image using VRmUsbCamFreeImage
  VRM_API VRmRetVal VRmUsbCamNewImage(VRmImage** fpp_image,VRmImageFormat f_image_format);

mein DELPHI-Code dazu:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
  type
    VRmBYTE = char;
    pVRmBYTE = ^VRmBYTE;
    VRmWORD = word;
    pVRmWORD = ^VRmWORD;
    VRmDWORD = dword;
    pVRmDWORD = ^VRmDWORD;
    VRmBOOL =  integer;
    VRmRetVal = (VRM_FAILED, VRM_SUCCESS);

    //Image Color Format
    VRmColorFormat = (VRM_ARGB_4X8, VRM_BGR_3X8, VRM_RGB_565, VRM_YUYV_4X8, VRM_GRAY_8,
                      VRM_BAYER_GBRG_8, VRM_BAYER_BGGR_8, VRM_BAYER_RGGB_8, VRM_BAYER_GRBG_8,
                      VRM_GRAY_10, VRM_BAYER_GBRG_10, VRM_BAYER_BGGR_10, VRM_BAYER_RGGB_10,
                    VRM_BAYER_GRBG_10);

    //Image Format
    VRmImageFormat = packed record
      m_width : VRmDWORD;
      m_height : VRmDWORD;
      m_color_format : VRmColorFormat;
      m_image_modifier : shortint;
    end;
    pVRmImageFormat = ^VRmImageFormat;

    //Image
    VRmImage = packed record
      m_image_format : VRmImageFormat;
      mp_buffer : pVRmByte;
      m_pitch : VRmDWORD;
      m_time_stamp : double;
      mp_private : pointer;
    end;
    pVRmImage = ^VRmImage;

  implementation

  function VRmUsbCamNewImage(var f_image : VRmImage; const f_image_format : VRmImageFormat) : VRmRetVal; cdecl;
                             external 'vrmusbcam2.dll' name 'VRmUsbCamNewImage';


Moderiert von user profile iconChristian S.: C- und Delphi-Tags hinzugefügt
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 19.01.07 12:18 
user profile iconEdmund Jenner-Braunschmie hat folgendes geschrieben:
Hallo Leute,

ich habe immer noch ein Problem beim Übersetzen eines Quelltextes aus C++ ins Delphi:

Die Funktion "VRmUsbCamNewImage" (ist in einer DLL) gibt immer FAILED zurück. Ich glaube das
Problem liegt in der Struktur für das VRmImage. Siehe unten die Codes!!

Was bedeutet
VRmBYTE* mp_buffer;
??

Das heißt, dass mp_buffer ein Zeiger auf eine Variable vom Typ VRmBYTE ist.
var mp_buffer: ^VRmBYTE;
Innerhalb einer struct ist das eine normale Felddefinition.

user profile iconEdmund Jenner-Braunschmie hat folgendes geschrieben:
Ist das ein Pointer auf ein Byte bzw. Char? In dem mp_buffer sollten nach erfolgreicher
Ausführung der Funktion eigentlich alle Daten eines Image (ähnlich wie eine Bitmap) liegen. Wie
kann das als Pointer auf 1 Byte funktionieren.

Man könnte alternativ dafür auch nen void* nehmen ... unsigned char* hat aber nen Vorteil, wenn man mit den Daten weiterarbeiten muss, weil man dann sofort damit rechnen kann.
Der Datentyp unsigned char entspricht in Delphi dem Datentyp Byte. Wenn ein Char gemeint ist, dann steht in C\C++ immer char ohne Attribut vorher da. Wobei man mit char unter C\C++ auch rechnen kann (entspricht dann dem Typ SmallInt von Delphi.

user profile iconEdmund Jenner-Braunschmie hat folgendes geschrieben:
Ach Gott C++ und die Pointer.....

Bitte um Hilfe und liebe Grüße

Edi

Hier der relevante C-Code:

ausblenden C-Code
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
  typedef unsigned char VRmBYTE; 
  typedef unsigned short int VRmWORD;
  typedef unsigned long int VRmDWORD; 
  typedef unsigned int VRmBOOL;

  typedef enum _VRmColorFormat
    { VRM_ARGB_4X8, VRM_BGR_3X8, VRM_RGB_565, VRM_YUYV_4X8, VRM_GRAY_8, VRM_BAYER_GBRG_8, VRM_BAYER_BGGR_8, VRM_BAYER_RGGB_8,
      VRM_BAYER_GRBG_8, VRM_GRAY_10, VRM_BAYER_GBRG_10, VRM_BAYER_BGGR_10, VRM_BAYER_RGGB_10, VRM_BAYER_GRBG_10
    }VRmColorFormat;

  /// struct for image format  
  typedef struct _VRmImageFormat
    { VRmDWORD m_width;
      VRmDWORD m_height;
      VRmColorFormat m_color_format;
      int m_image_modifier;
    }VRmImageFormat;

  /// struct for image container
  typedef struct _VRmImage
    { VRmImageFormat m_image_format;
      VRmBYTE* mp_buffer;
      VRmDWORD m_pitch;
      double m_time_stamp;
      void* mp_private;
    }VRmImage;

  /// create new image with given image format,
  /// free image using VRmUsbCamFreeImage
  VRM_API VRmRetVal VRmUsbCamNewImage(VRmImage** fpp_image,VRmImageFormat f_image_format);

mein DELPHI-Code dazu:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
  type
    VRmBYTE = char; //Siehe Kommentar zwecks Byte\Char ;-)
    pVRmBYTE = ^VRmBYTE;
    VRmWORD = word;
    pVRmWORD = ^VRmWORD;
    VRmDWORD = dword;
    pVRmDWORD = ^VRmDWORD;
    VRmBOOL =  integer; //Übersetz das bitte lieber mit BOOL bzw. LONGBOOL
    VRmRetVal = (VRM_FAILED, VRM_SUCCESS);

    //Image Color Format
    VRmColorFormat = (VRM_ARGB_4X8, VRM_BGR_3X8, VRM_RGB_565, VRM_YUYV_4X8, VRM_GRAY_8,
                      VRM_BAYER_GBRG_8, VRM_BAYER_BGGR_8, VRM_BAYER_RGGB_8, VRM_BAYER_GRBG_8,
                      VRM_GRAY_10, VRM_BAYER_GBRG_10, VRM_BAYER_BGGR_10, VRM_BAYER_RGGB_10,
                    VRM_BAYER_GRBG_10);

    //Image Format
    VRmImageFormat = packed record
      m_width : VRmDWORD;
      m_height : VRmDWORD;
      m_color_format : VRmColorFormat;
      m_image_modifier : shortint; //Int ist mindesnts so lang wie'n short und maximal so lang wie'n long ;-) In diesem Fall ist int ein LongInt\Integer in Delphi
    end;
    pVRmImageFormat = ^VRmImageFormat;

    //Image
    VRmImage = packed record
      m_image_format : VRmImageFormat;
      mp_buffer : pVRmByte;
      m_pitch : VRmDWORD;
      m_time_stamp : double;
      mp_private : pointer;
    end;
    pVRmImage = ^VRmImage;

  implementation

  function VRmUsbCamNewImage(var f_image : VRmImage; const f_image_format : VRmImageFormat) : VRmRetVal; cdecl;
                             external 'vrmusbcam2.dll' name 'VRmUsbCamNewImage';


Moderiert von user profile iconChristian S.: C#- und Delphi-Tags hinzugefügt


Ansonsten schau mal, ob die Datenstrukturen für das C++-Programm wie erwartet ankommen ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
perry5
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Fr 19.01.07 16:47 
VRmBYTE* mp_buffer ist wie erwähnt ein Zeiger auf ein mp_buffer und gleichzeitig ein Feld.
Man benutzt einen Zeiger in C++ eigentlich imemr, wenn die Feldgröße noch nicht bekannt ist. IOm Prinzip ist in C++ ein Feld imemr ein Zeiger auf der erste Element, durch [x] wird der entsprechende Wert auf den Zeiger addiert, um eben auf das x-te Element, zuzugreifen.

Hm, SmallInt ist 16bit, oder? Steht jedenfalls ind er Hilfe.
Dann wäre das aber kein C++ char, den der hat nur 8 Bit.
Und von char gibt es signed und unsigned, welches Standard ist, also genommen wird, wenn nichts anderes angegeben ist, ist Compilerabhängig.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 19.01.07 16:51 
user profile iconperry5 hat folgendes geschrieben:
VRmBYTE* mp_buffer ist wie erwähnt ein Zeiger auf ein mp_buffer und gleichzeitig ein Feld.
Man benutzt einen Zeiger in C++ eigentlich imemr, wenn die Feldgröße noch nicht bekannt ist. IOm Prinzip ist in C++ ein Feld imemr ein Zeiger auf der erste Element, durch [x] wird der entsprechende Wert auf den Zeiger addiert, um eben auf das x-te Element, zuzugreifen.

Korrekt ;-)

user profile iconperry5 hat folgendes geschrieben:
Hm, SmallInt ist 16bit, oder? Steht jedenfalls ind er Hilfe.
Dann wäre das aber kein C++ char, den der hat nur 8 Bit.

Nope ... Was Du meinst, ist ShortInt ... Naja, einer von beiden *g* Richtige Programmierer nutzen keine Bytes mit Vorzeichen :twisted:

user profile iconperry5 hat folgendes geschrieben:
Und von char gibt es signed und unsigned, welches Standard ist, also genommen wird, wenn nichts anderes angegeben ist, ist Compilerabhängig.
Nope ... char ohne was davor in C ist ein signed-Datentyp ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Fr 19.01.07 17:16 
user profile iconBenBE hat folgendes geschrieben:
Nope ... char ohne was davor in C ist ein signed-Datentyp ...
In C++ ist es undefiniert, was die Vermutung nahe legt, daß es in C auch undefiniert war (den Standard habe ich mir nicht besorgt). Der G++ (4.1.2) interpretiert char aber als signed char.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
perry5
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Fr 19.01.07 17:21 
Also im Visual C++ kann mans umstellen, ob stnadradmäßig signed oder unsigned sein soll. Was im Standard steht beeinflusst ja nicht die Aussage, das es Kompilerabhängig ist, weil nicht jeder Compiler sich an den Standard hält :-)

Joah, und Sinn macht signed char zum rechnen echt nicht, es gibt ja auch n typedef, das ein Byte als unsigned char definniert, was man dann meistens nimmt.
Aber signed char ginge auch.