?
Solved

More C type questions...

Posted on 1999-07-13
3
Medium Priority
?
187 Views
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                             ))

and
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
end;

TUnionRec2 = Record
end;

MyRecord = Record
  UnionRec1 : TUnionRec1;
  UnionRec2 : TUnionRec2;
end;

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...
0
Comment
Question by:jonnyfive
[X]
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
3 Comments
 
LVL 12

Accepted Solution

by:
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:

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

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...)

Cheers,

Raymond.

0
 

Author Comment

by:jonnyfive
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? :-)

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1388274
The closest translation to this is:

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

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

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).

Cheers,

Raymond.

0

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