Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi C-Code zu Delphi (SharedMem) (https://www.delphipraxis.net/117511-c-code-zu-delphi-sharedmem.html)

El.Blindo 19. Jul 2008 14:28


C-Code zu Delphi (SharedMem)
 
Moin, Moin,

Für eines meiner Projekte muss ich ein wenig C-Code in Delphi umwandeln, genaugenommen geht es dabei um Zugriff auf den Shared-Memory Bereich eines anderen Programmes.

Erst einmal der C-Code

Zitat:

#define SHMEM_NAME _T("GPUZShMem")
#define MAX_RECORDS 128

#pragma pack(push, 1)
struct GPUZ_RECORD
{
WCHAR key[256];
WCHAR value[256];
};

struct GPUZ_SENSOR_RECORD
{
WCHAR name[256];
WCHAR unit[8];
UINT32 digits;
double value;
};

struct GPUZ_SH_MEM
{
UINT32 version; // Version number, 1 for the struct here
volatile LONG busy; // Is data being accessed?
UINT32 lastUpdate; // GetTickCount() of last update
GPUZ_RECORD data[MAX_RECORDS];
GPUZ_SENSOR_RECORD sensors[MAX_RECORDS];
};
#pragma pack(pop)
Nun meine Umsetzung

Delphi-Quellcode:
  tGPUZ_Record = packed record
    GPUZ_Key   : Array [0..255] of WChar;
    GPUZ_Value : Array [0..255] of WChar;
  end;

  tGPUZ_Sensors = packed record
    GPUZ_Name  : Array [0..255] of WChar;
    GPUZ_Unit  : Array [0..7] of WChar;
    GPUZ_Digits : DWord;
    GPUZ_Value : Double;
  End;

  tGPUZShMem=packed record
    Version    : DWord;
    Busy       : Longint;
    LastUpdate : DWord;
    Daten      : Array[0..127] of tGPUZ_Record;
    Sensors    : Array[0..127] of tGPUZ_Sensors;
  end;

  PGPUZShMem = ^tGPUZShMem;
Ich bin mir aber absolut nicht sicher ob diese Umsetzung richtig ist, besonders da ich in meinem Projekt gelegentlich ein Exception bekomme, leider ohne Hinweis auf die Adresse.

Ich wäre also dankbar wenn mir jemand bestätigen könnte das mein Code richtig ist, oder aber Aufzeigen könnte was daran falsch ist.

Mfg

El-Blindo

[edit=Phoenix]Tippfehler im Titel korrigiert. Mfg, Phoenix[/edit]

generic 6. Aug 2008 15:04

Re: C-Code zu Delhi (SharedMem)
 
Du könntest ist beiden Programmiersprachen mit Size die Struktur prüfen.
Wenn die Größe gleich ist, dann hast du es richtig übersetzt.

christian_u 6. Aug 2008 15:56

Re: C-Code zu Delphi (SharedMem)
 
das #pragma pack schaut für mich so aus als sollte es ein packet record sein...

El.Blindo 16. Aug 2008 00:18

Re: C-Code zu Delphi (SharedMem)
 
Deshalb ist es ja auch ein packed record.
Ich weiss zwar immer noch nicht ob das ganze 100% richtig ist, aber immerhin funktioniert es so.


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