![]() |
Delphi-Version: 2010
Hilfe beim Übersetzen von C++ zu Delphi
Hallo DPler,
ich möchte diese C++ Struktur nach Delphi übersetzen: C++:
Code:
...meine Übersetzung nach Delphi:
typedef struct {
PARTITION_STYLE PartitionStyle; union { CREATE_DISK_MBR Mbr; CREATE_DISK_GPT Gpt; }; } CREATE_DISK, *PCREATE_DISK;
Delphi-Quellcode:
Das sollte doch so funktionieren, oder?! :(
_CREATE_DISK = packed record
PartitionsStyle: PARTITION_STYLE; Mbr: CREATE_DISK_MBR; Gpt: CREATE_DISK_GPT; end; CREATE_DISK = _CREATE_DISK; PCREATE_DISK = ^CREATE_DISK; Oder wie soll ich diese "union structure" sonst nach Delphi übersetzen? Danke für jeden Tipp! :) |
AW: Hilfe beim Übersetzen von C++ zu Delphi
Delphi-Quellcode:
Auf was du aber noch aufpassen mußt, ist die Speicher-/Feldausrichtung, also daß diese wirklich korrekt ist, denn von "packed" steht in dem C-Code nichts drin.
_CREATE_DISK = packed record
PartitionsStyle: PARTITION_STYLE; case Integer of 0: (Mbr: CREATE_DISK_MBR); 1: (Gpt: CREATE_DISK_GPT); end; // oder _CREATE_DISK = packed record case PartitionsStyle: PARTITION_STYLE of 0: (Mbr: CREATE_DISK_MBR); 1: (Gpt: CREATE_DISK_GPT); end; // statt 0 und 1 besser die "korrekten" Werte einsetzen oder gar die passenden Konstanten ... für die Funktion isses aber unerheblich |
AW: Hilfe beim Übersetzen von C++ zu Delphi
Hallo himitsu,
danke für dieses Beispiel. Zitat:
|
AW: Hilfe beim Übersetzen von C++ zu Delphi
Sowas wie das "packed" selber hab ich noch nie gesehn,
aber das
Delphi-Quellcode:
, bzw.
{$A...}
Delphi-Quellcode:
ist dort nicht immer so definiert, wie es in Delphi standardmäßig der Fall ist.
{$ALIGN ...}
Und jenachdem von wo man den Code hat, gibt es in den C-Header entweder eine entsprechende Definition, bzw. dort existiert eine bestimmte "Vorgabe", in den übergeordneten Headern. Auch die ENUMs stimmen nicht immer überein.
Delphi-Quellcode:
z.B. in Delphi sind die standardmäßig so klein wie möglich (in diesem Fall 1 Byte)
_PARTITION_STYLE = (
PARTITION_STYLE_MBR, PARTITION_STYLE_GPT, PARTITION_STYLE_RAW); und in C++ sind sie so wie die Register (für ein 32 Bit Programm dann 32 Bit = 4 Byte) |
AW: Hilfe beim Übersetzen von C++ zu Delphi
Danke himitsu! Du bist eine große Hilfe :)
|
AW: Hilfe beim Übersetzen von C++ zu Delphi
Vergess jedesmal wie das MINENUMSIZE lautet ... also hier nochmal in Kurz
Delphi-Quellcode:
oder im Notfall einfach so
type
{$MINENUMSIZE 4} _PARTITION_STYLE = ( PARTITION_STYLE_MBR, PARTITION_STYLE_GPT, PARTITION_STYLE_RAW); {$MINENUMSIZE 1}
Delphi-Quellcode:
type
_PARTITION_STYLE = type Integer; const PARTITION_STYLE_MBR = _PARTITION_STYLE(0); PARTITION_STYLE_GPT = _PARTITION_STYLE(1); PARTITION_STYLE_RAW = _PARTITION_STYLE(2); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:02 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz