More C type questions...

Posted on 1999-07-13
Medium Priority
Last Modified: 2010-04-06
Hi everyone...

how do I translate the following to Delphi 4?

#define TCOMPfromTypeLevelMemory(t,l,m)           \
            (((m) << tcompSHIFT_QUANTUM_MEM  ) |  \
             ((l) << tcompSHIFT_QUANTUM_LEVEL) |  \
             ( t                             ))

typedef struct {
    FDIDECRYPTTYPE    fdidt;            // Command type (selects union below)
    void FAR         *pvUser;           // Decryption context
    union {
        struct {                        // fdidtNEW_CABINET
            void FAR *pHeaderReserve;   // RESERVE section from CFHEADER
            USHORT    cbHeaderReserve;  // Size of pHeaderReserve
            USHORT    setID;            // Cabinet set ID
            int       iCabinet;         // Cabinet number in set (0 based)
        } cabinet;

        struct {                        // fdidtNEW_FOLDER
            void FAR *pFolderReserve;   // RESERVE section from CFFOLDER
            USHORT    cbFolderReserve;  // Size of pFolderReserve
            USHORT    iFolder;          // Folder number in cabinet (0 based)
        } folder;

        struct {                        // fdidtDECRYPT
            void FAR *pDataReserve;     // RESERVE section from CFDATA
            USHORT    cbDataReserve;    // Size of pDataReserve
            void FAR *pbData;           // Data buffer
            USHORT    cbData;           // Size of data buffer
            BOOL      fSplit;           // TRUE if this is a split data block
            USHORT    cbPartial;        // 0 if this is not a split block, or
                                        //  the first piece of a split block;
                                        // Greater than 0 if this is the
                                        //  second piece of a split block.
        } decrypt;
} FDIDECRYPT; /* fdid */

I don't have a problem here with the data types, but with the keyword "union". Do I see it right, that I have to declare the structs (Records) inside the union in my type declarations as normal records and then do something like:

TUnionRec1 = Record

TUnionRec2 = Record

MyRecord = Record
  UnionRec1 : TUnionRec1;
  UnionRec2 : TUnionRec2;

Would this be correct? If sombody know where I could find a allready finished translation of the FDI.H file (From the MS CABS SDK), it wouldn't mind to getting my hands on it ;-)Thanks, Jonny...
Question by:jonnyfive
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 12

Accepted Solution

rwilson032697 earned 200 total points
ID: 1388272
A Union means that the 'variants' within it are stored in the same memory. In your case it would look like this:

MyRecord = record
  case integer of
    0 : UnionRec1 : TUnionRec1;
    1 : UnioneRec2 : TUnionRec2;

The help on unions is pretty good in Delphi.

I don't know if there is an converted FDI.H file, perhaps you could look at the Jedi Project home page (whose URL escapes me at the moment...)




Author Comment

ID: 1388273
Hi Raymund...

Thanks for your answer... could you tell me how I convert the first Part of what I posted?

#define TCOMPfromTypeLevelMemory(t,l,m)           \
            (((m) << tcompSHIFT_QUANTUM_MEM  ) |  \
             ((l) << tcompSHIFT_QUANTUM_LEVEL) |  \
             ( t                             ))

And do I see it right, that I would have to use it then in this particular case like
Case PVUSER of ... and what does the FAR statment mean? :-)

LVL 12

Expert Comment

ID: 1388274
The closest translation to this is:

Function TCOMPfromTypeLevelMemory(t,l,m : Integer) : Integer;

  Result := (t SHL tcompSHIFT_QUANTUM_MEM) OR
            (l SHL tcompSHIFT_QUANTUM_LEVEL) OR t;

Though, as you can see, you could just inline this (which is the ultimate effect in the C code).

The void FAR *pvUser is defining a pvUser as a pointer to void (C way of saying a generic pointer). It is not related to the union which has fdidt as the tag.

FAR is redundant in Win32, basically it meant a pointer which could reference a location outside of the current 64k memory segment (in 16-bit windows land).




Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question