Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   cpp to delphi struct Problem (https://www.delphipraxis.net/77165-cpp-delphi-struct-problem.html)

duff 15. Sep 2006 13:54


cpp to delphi struct Problem
 
Hallo Leute,

ich habe ein Problem mit folgender cpp Struktur:

Code:
typedef struct
{
  LONG            nSize;                            // size of the struct
  TCHAR           sCountry[MAXLEN_COUNTRY];         // country
  TCHAR           sCity[MAXLEN_CITY];               // city
  TCHAR           sZipCode[MAXLEN_ZIPCODE];         // postal code
  TCHAR           sStreet[MAXLEN_STREET];           // street
  TCHAR           sHouseNumber[MAXLEN_HOUSENUMBER]; // housenumber
  float           fX;                               // x position
  float           fY;                               // y position
  NCK_COORD_FORMAT coordFormat;                      // format 0:WGS84, 1:Gauss-Krueger
  NCKErrorStatus  errStatus;                        // error status in case of conversion
} NCKTarget;
Code:
#define MAXLEN_COUNTRY          10    // country
#define MAXLEN_CITY            100    // city
#define MAXLEN_ZIPCODE          20    // postal code
#define MAXLEN_STREET          100    // street
#define MAXLEN_HOUSENUMBER      20    // housenumber
#define MAXLEN_MESSAGE         128    // message for status
#define MAXLEN_GPSSTRING       256    // GPS string
Meine Delphi Übersetzung

Delphi-Quellcode:
type
  TNCKTarget = record
    nSize: integer;                    // size of the struct
    sCountry: array[0..9] of char;     // country
    sCity: array[0..99] of char;       // city
    sZipCode: array [0..19] of char;   // postal code
    sStreet: array[0..99] of char;     // street
    sHouseNumber: array[0..19] of char; // housenumber
    fX: single;                        // x position
    fY: single;                        // y position
    coordFormat: NCK_COORD_FORMAT;     // format 0:WGS84, 1:Gauss-Krueger
    errStatus: TNCKErrorStatus;        // error status in case of conversion
  end;
Nun ist es so, dass in der cpp Anwendung das Struct 400 Bytes hat und die Delphiversion 396 Bytes. Was mache ich falsch? Liegt es vielleicht an den Aufzählungstypen?? Wäre schön wenn jemand helfen könnte!!

Delphi-Quellcode:
type
  NCK_COORD_FORMAT = (COORD_FORMAT_WGS84 = 0, COORD_FORMAT_GK = 1);
Code:
enum NCK_COORD_FORMAT
{
   COORD_FORMAT_WGS84 = 0,
   COORD_FORMAT_GK
};


Delphi-Quellcode:
type
  NCK_ERROR_CODE = (NCKERR_OK = 0, NCKERR_CONVERT_COORD_TO_ADDRESS = 1,
    NCKERR_CONVERT_ADDRESS_TO_COORD = 3);
Code:
enum NCK_ERROR_CODE
{
   NCKERR_OK = 0,
   NCKERR_CONVERT_COORD_TO_ADDRESS,
   NCKERR_CONVERT_ADDRESS_TO_COORD
};

Phantom1 15. Sep 2006 14:25

Re: cpp to delphi struct Problem
 
Was issn "TNCKErrorStatus" bzw wie ist dieser Typ aufgebaut? Falls das "NCK_ERROR_CODE" sein soll, hat der Typ "TNCKTarget" als packet record bei mir nur 264 Byte und nicht 396 Byte!

mfg

duff 15. Sep 2006 15:34

Re: cpp to delphi struct Problem
 
oh hab ich vergessen zu posten...

Delphi-Quellcode:
type
  TNCKErrorStatus = record
    nCode:   NCK_ERROR_CODE;                    // status code, 0: Ok, >0: error
    sMessage: array[0..127] of char;             // status message in case of error
  end;

CalganX 15. Sep 2006 15:45

Re: cpp to delphi struct Problem
 
Hi,
ich glaube man kann da irgendwas mit der Anweisung Delphi-Referenz durchsuchenpacked record statt record machen. Was genau, weiß ich nicht - einfach mal ausprobieren. ;)

Ansonsten vllt. einfach Dummyfelder einbauen?

Chris

Flocke 15. Sep 2006 17:04

Re: cpp to delphi struct Problem
 
Zitat:

Zitat von duff
Liegt es vielleicht an den Aufzählungstypen??

Ich denke ja - Delphi optimiert die Größe von Aufzählungstypen je nach Anzahl der Elemente (1, 2 oder 4 Byte), während in C/C++ ein enum (fast) immer die Größe eines Integers hat.

Probiere mal {$MINENUMSIZE 4}.

ste_ett 15. Sep 2006 17:32

Re: cpp to delphi struct Problem
 
Zitat:

Zitat von Chakotay1308
Ansonsten vllt. einfach Dummyfelder einbauen?

Davon würde ich dringend abraten. :)

Die Record-Struktur ist bei mir 400 Byte groß.
"packed record", wie schon genannt, ist das Stichwort. :)

Delphi-Quellcode:
TNCKErrorStatus = packed record
(*  *)
end;

TNCKTarget = packed record
(*  *)
end;

duff 15. Sep 2006 19:26

Re: cpp to delphi struct Problem
 
bei packed record war mein record 392 byte groß

aber {$MinEnumSize 4} hat geholfen

danke leute schönes wochenende

Robert Marquardt 16. Sep 2006 06:04

Re: cpp to delphi struct Problem
 
Ich will hier nochmal bestaetigen: Enums sind in C/C++ immer 4 Byte gross.
Das liegt daran das sie in C den Integern deutlich naeher verwandt sind als bei Pascal.

duff 18. Sep 2006 11:39

Re: cpp to delphi struct Problem
 
jetzt müsst ihr mir nochmal weiterhelfen...

ich denke mit dem Record ist jetzt alles OK

Delphi-Quellcode:
sendMessage(serverhandle, wm_CopyData, 0, integer(@acopydata));
Dieses sendMessage gibt mir nun auch ne 1 zurück (war mit falschem Record noch ne 0) nur bekomme ich irgendwie kein wm_CopyData von der Fremdapplication zurück.

Delphi-Quellcode:
procedure TNavigon.appmessage(var Msg: TMsg; var Handled: boolean);
begin
  if msg.message = NCK_ANNOUNCE_SERVER_TO_CLIENT then
  begin
    serverhandle := msg.lParam;
    frmmain.Form1.JvMemo1.Lines.Add('Serverhandle: ' + IntToStr(serverhandle));
    writeln('Serverhandle: ' + IntToStr(serverhandle));
  end;

  if msg.message = WM_COPYDATA then // hier kommt kein WM_COPYDATA an
    frmmain.Form1.JvMemo1.Lines.Add('WM_COPYDATA');

end;
Mach ich da noch was falsch?


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