Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi to C++ (Few Lines)

Posted on 2007-03-20
16
Medium Priority
?
415 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:-Karamja-
[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
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 18757152
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
 
LVL 86

Expert Comment

by:jkr
ID: 18758729
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
 
LVL 2

Author Comment

by:-Karamja-
ID: 18759121
Yes, just playing around with it and
typedef IMAGE_SECTION_HEADER TSections;

Seems to be close, but what about the array part?
0
Independent Software Vendors: 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!

 
LVL 86

Expert Comment

by:jkr
ID: 18759359
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
 
LVL 2

Author Comment

by:-Karamja-
ID: 18759688
Ok thanks for your reply guys,

I cant do anymore testing until tomorrow, I will get back to you then.
0
 
LVL 86

Expert Comment

by:jkr
ID: 18759836
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 18760205
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
 
LVL 21

Expert Comment

by:ziolko
ID: 18762606
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 18762745
ziolko, for this :

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

would the equivalent in C++ be :

    typedef TImageSectionHeader* TSections

or :

    typedef TImageSectionHeader TSections;

???
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18762773
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 18762836
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
 
LVL 2

Author Comment

by:-Karamja-
ID: 18762866
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 18762991
>> 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
 
LVL 2

Author Comment

by:-Karamja-
ID: 18763055
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 18763264
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
 
LVL 2

Author Comment

by:-Karamja-
ID: 18763328
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

688 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