Delphi to C++ (Few Lines)

Hello,

Can anyone quickly help converting these few lines of Delphi to C++

type
  TSections = array [0..0] of TImageSectionHeader;

var
PSections: ^TSections;

So in C++, TImageSectionHeader is IMAGE_SECTION_HEADER, and would be like this
PSections* TSections; and maybe the type gets changed into a struct? Gah im so confused, help? :P

Cheers.
LVL 2
-Karamja-Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
I don't know enough Delphi to know what this means :

    array [0..0]

an array of size 0 ???

In any case, I think that it might be something like this in C++ :

    typedef TImageSectionHeader* TSections

    TSections *PSections;

Again, I can't be sure since I don't know enough Delphi.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
Actually, if I remember my PASCAL times correctly, that should be

typedef IMAGE_SECTION_HEADER TSections;

TSections* pSections;

If you want to create a pointer to a IMAGE_SECTION_HEADER structure.
0
-Karamja-Author Commented:
Yes, just playing around with it and
typedef IMAGE_SECTION_HEADER TSections;

Seems to be close, but what about the array part?
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

jkrCommented:
In C/C++ arrays and pointers are (well almost) interchangeable, so that should not play a role here. E.g.

int array[10];

*array = 0;

int n = *array

is the same as

array[0] = 0;

int n = array[0];
0
-Karamja-Author Commented:
Ok thanks for your reply guys,

I cant do anymore testing until tomorrow, I will get back to you then.
0
jkrCommented:
Oh, until tomorrow, you'll probably find some essays as comments that deal with the philosophic depth of the array/pointer similarity and borderline cases where that might be dangerous ;o)
0
Infinity08Commented:
jkr, do you know what this means in Delphi ?

    array [0..0]

I assumed that it was a 0-length array, and thus defined it as a pointer only.
0
ziolkoCommented:
array[0..0] means array of any length (but you need range checking off so no range check error is thrown in run-time)

basically with delphi you would use array of ... if you want dynamic variable length array, array[0..0] is used with windows API.

ziolko.
0
Infinity08Commented:
ziolko, for this :

    type
      TSections = array [0..0] of TImageSectionHeader;

would the equivalent in C++ be :

    typedef TImageSectionHeader* TSections

or :

    typedef TImageSectionHeader TSections;

???
0
ziolkoCommented:
i'm not that good in c++ but in delphi i've got:

  PDS_SELECTION_LIST = ^DS_SELECTION_LIST;
  DS_SELECTION_LIST = record
    cItems: ULONG;
    cFetchedAttributes: ULONG;
    aDsSelection: array[0..0] of DS_SELECTION;
  end;

and according to MDSN it's equivalent to:

typedef struct _DS_SELECTION_LIST {  ULONG cItems;  ULONG cFetchedAttributes;  DS_SELECTION aDsSelection[ANYSIZE_ARRAY];
} DS_SELECTION_LIST, *PDS_SELECTION_LIST;


maybe this will help you somehow

ziolko.
0
Infinity08Commented:
That fits my understanding of the Delphi code.

That means that my original hunch :

    typedef TImageSectionHeader* TSections

    TSections *PSections;

seems correct.
So, TSections is a dynamically-sized array of TImageSectionHeader
And PSections is a pointer to such an array.


Can anyone confirm that ?
0
-Karamja-Author Commented:
But isnt,

TImageSectionHeader* same as PTImageSectionHeader
or
IMAGE_SECTION_HEAEDER* = PIMAGE_SECTION_HEADER

And im just looking for IMAGE_SECTION_HEADER with my var as a pointer to it, Anyway,
I will do some testing in a minute and see what happens.
0
Infinity08Commented:
>> IMAGE_SECTION_HEAEDER* = PIMAGE_SECTION_HEADER

Well, in C++, that would be :

    typedef IMAGE_SECTION_HEAEDER* PIMAGE_SECTION_HEADER

which is the same as (just different names) :

    typedef TImageSectionHeader* TSections



And then used as :

    PIMAGE_SECTION_HEADER *PSections;

which is the same as (just different names) :

    TSections *PSections;



Am I missing something ?
0
-Karamja-Author Commented:
Lets just go back to the Delphi code,

type
  TSections = array [0..0] of TImageSectionHeader;

var
PSections: ^TSections;

^ is the same as * in C++, and TImageSectionHeader is the same as IMAGE_SECTION_HEADER.
So what im trying to get, is a pointer of var that is a type of IMAGE_SECTION_HEADER.
What your saying is, pointer of var that is that is a type of PIMAGE_SECTION_HEADER.

Remembering that PIMAGE_SECTION_HEADER is just IMAGE_SECTION_HEADER*

This so confusing :( maybe I am missing something too?
0
Infinity08Commented:
Yes, but TSections is not defined as a single TImageSectionHeader, but as an array of TImageSectionHeader (of undefined length).

In C++, and array can be defined like this :

    TImageSectionHeader  array[10];

this defines an array of 10 TImageSectionHeader. The problem here is that we need to know how big the array is gonna be.
Since Delphi uses a dynamic array (of undefined length), we most likely need to do the same thing in C++.

A dynamic array in C++ is done like this :

    TImageSectionHeader  *array;

now, we can allocate memory for that array once we know how much elements we want (say we want 10) :

    array = new TImageSectionHeader[10];
    // use the array
    delete [] array;

That's why I (with my limited knowledge of Delphi) used this typedef :

    typedef TImageSectionHeader* TSections

ie. TSections is defined as a dynamic array (of undefined length) of TImageSectionHeader
0
-Karamja-Author Commented:
Ahh, that seems to fit.
Sorry for all the confusion, I should be able to make tests soon and will get back to everyone then.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.